import { createCrudRoutes } from '@d8d/shared-crud';
import { RoleMt } from '../entities/role.entity.mt';
import { RoleSchemaMt, CreateRoleDtoMt, UpdateRoleDtoMt } from '../schemas/role.schema.mt';
import { OpenAPIHono } from '@hono/zod-openapi';
import { authMiddleware } from '@d8d/auth-module-mt';

// 创建多租户角色CRUD路由
const roleRoutesMt = createCrudRoutes({
  entity: RoleMt,
  createSchema: CreateRoleDtoMt,
  updateSchema: UpdateRoleDtoMt,
  getSchema: RoleSchemaMt,
  listSchema: RoleSchemaMt,
  searchFields: ['name', 'description'],
  middleware: [
    authMiddleware,
    // permissionMiddleware(checkPermission(['role:manage']))
  ],
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId',
    autoExtractFromContext: true
  }
})

const app = new OpenAPIHono()
  .route('/', roleRoutesMt)

// .route('/', customRoute)

export default app;