import { OpenAPIHono } from '@hono/zod-openapi';
import { createCrudRoutes } from '@d8d/shared-crud';
import { SystemConfig } from '../entities/system-config.entity';
import { SystemConfigSchema, CreateSystemConfigSchema, UpdateSystemConfigSchema } from '../schemas/system-config.schema';
import { authMiddleware } from '../../../auth-module/src/middleware/index';
import createSystemConfigRoutes from './custom/create-system-config';
import updateSystemConfigRoutes from './custom/update-system-config';
import deleteSystemConfigRoutes from './custom/delete-system-config';

const systemConfigCrudRoutes = createCrudRoutes({
  entity: SystemConfig,
  createSchema: CreateSystemConfigSchema,
  updateSchema: UpdateSystemConfigSchema,
  getSchema: SystemConfigSchema,
  listSchema: SystemConfigSchema,
  searchFields: ['configKey', 'description'],
  middleware: [authMiddleware],
  readOnly: true // 设为只读，创建、更新、删除操作通过自定义路由处理
});

// 创建路由实例 - 聚合自定义路由和CRUD路由
const systemConfigRoutes = new OpenAPIHono()
  .route('/', createSystemConfigRoutes)
  .route('/', updateSystemConfigRoutes)
  .route('/', deleteSystemConfigRoutes)
  .route('/', systemConfigCrudRoutes);

export { systemConfigRoutes };
export default systemConfigRoutes;