import { createCrudRoutes } from '../../../utils/generic-crud.routes';
import { authMiddleware } from '../../../middleware/auth.middleware';
import { AreaEntity } from '../../../modules/areas/area.entity';
import {
  createAreaSchema,
  updateAreaSchema,
  getAreaSchema,
  areaListResponseSchema
} from '../../../modules/areas/area.schema';
import treeRoutes from './tree';
import { OpenAPIHono } from '@hono/zod-openapi';

// 使用通用CRUD路由创建省市区管理API
const areaRoutes = createCrudRoutes({
  entity: AreaEntity,
  createSchema: createAreaSchema,
  updateSchema: updateAreaSchema,
  getSchema: getAreaSchema,
  listSchema: areaListResponseSchema,
  searchFields: ['name', 'code'],
  relations: ['parent', 'children'],
  middleware: [authMiddleware]
})

export default new OpenAPIHono()
  // 合并树形结构路由
  .route('/', treeRoutes)
  .route('/', areaRoutes);

