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

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

// 合并树形结构路由
.route('/', treeRoutes);

