import { OpenAPIHono } from '@hono/zod-openapi';
import { createCrudRoutes } from '@d8d/shared-crud';
import { UserEntityMt } from '../../src/entities/user.entity.mt';
import { UserSchemaMt, CreateUserDtoMt, UpdateUserDtoMt } from '../../src/schemas/user.schema.mt';

// 创建多租户通用CRUD路由配置（测试版本，不包含认证中间件）
const userCrudRoutesMt = createCrudRoutes({
  entity: UserEntityMt,
  createSchema: CreateUserDtoMt,
  updateSchema: UpdateUserDtoMt,
  getSchema: UserSchemaMt,
  listSchema: UserSchemaMt,
  searchFields: ['username', 'nickname', 'phone', 'email'],
  relations: ['roles'],
  readOnly: false, // 启用所有CRUD操作
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId',
    autoExtractFromContext: true
  }
});

// 创建多租户混合路由应用（测试版本）
const app = new OpenAPIHono()
  .route('/', userCrudRoutesMt); // 多租户通用CRUD路由

export default app;