import { createCrudRoutes } from '@d8d/shared-crud';
import { authMiddleware } from '@d8d/auth-module-mt';
import { AreaEntityMt } from '../../../modules/areas/area.entity.mt';
import {
  createAreaSchemaMt as createAreaSchema,
  updateAreaSchemaMt as updateAreaSchema,
  getAreaSchemaMt as getAreaSchema,
  areaListResponseSchemaMt as areaListResponseSchema
} from '../../../modules/areas/area.schema.mt';
import treeRoutes from './tree.mt';
import { OpenAPIHono } from '@hono/zod-openapi';

// 使用通用CRUD路由创建省市区管理API（多租户版本）
const areaRoutes = createCrudRoutes({
  entity: AreaEntityMt,
  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;