import { createCrudRoutes } from '@d8d/shared-crud';
import { authMiddleware } from '@d8d/core-module/auth-module';
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]
})
const app = new OpenAPIHono()
  // 合并树形结构路由
  .route('/', treeRoutes)
  .route('/', areaRoutes);
export default app;