import { OpenAPIHono } from '@hono/zod-openapi';
import { createCrudRoutes } from '@d8d/shared-crud';
import { SystemConfigMt } from '../entities/system-config.entity.mt';
import { SystemConfigSchema, CreateSystemConfigSchema, UpdateSystemConfigSchema } from '../schemas/system-config.schema.mt';
import { authMiddleware } from '../../../auth-module-mt/src/middleware/index.mt';

const systemConfigCrudRoutes = createCrudRoutes({
  entity: SystemConfigMt,
  createSchema: CreateSystemConfigSchema,
  updateSchema: UpdateSystemConfigSchema,
  getSchema: SystemConfigSchema,
  listSchema: SystemConfigSchema,
  searchFields: ['configKey', 'description'],
  middleware: [authMiddleware],
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId',
    autoExtractFromContext: true
  }
});

// 创建路由实例
const systemConfigRoutesMt = new OpenAPIHono()
  .route('/', systemConfigCrudRoutes);

export { systemConfigRoutesMt };
export default systemConfigRoutesMt;