import { OpenAPIHono } from '@hono/zod-openapi';
import { createCrudRoutes } from '../../utils/generic-crud.routes';
import { UserEntity } from '../../modules/users/user.entity';
import { UserSchema, CreateUserDto, UpdateUserDto } from '../../modules/users/user.schema';
import { authMiddleware } from '../../middleware/auth.middleware';
import customRoutes from './custom';

// 创建通用CRUD路由配置
const userCrudRoutes = createCrudRoutes({
  entity: UserEntity,
  createSchema: CreateUserDto,
  updateSchema: UpdateUserDto,
  getSchema: UserSchema,
  listSchema: UserSchema,
  searchFields: ['username', 'nickname', 'phone', 'email'],
  relations: ['roles'],
  middleware: [authMiddleware],
  readOnly: true // 创建/更新/删除使用自定义路由
});

// 创建混合路由应用
const app = new OpenAPIHono()
  .route('/', customRoutes)   // 自定义业务路由（创建/更新/删除）
  .route('/', userCrudRoutes); // 通用CRUD路由（列表查询和获取详情）

export default app;