import { createCrudRoutes } from '@d8d/shared-crud';
import { Role } from '../entities/role.entity';
import { RoleSchema, CreateRoleDto, UpdateRoleDto } from '../schemas/role.schema';
import { OpenAPIHono } from '@hono/zod-openapi';
import { authMiddleware } from '@d8d/auth-module';

// 创建角色CRUD路由
const roleRoutes = createCrudRoutes({
  entity: Role,
  createSchema: CreateRoleDto,
  updateSchema: UpdateRoleDto,
  getSchema: RoleSchema,
  listSchema: RoleSchema,
  searchFields: ['name', 'description'],
  middleware: [
    authMiddleware,
    // permissionMiddleware(checkPermission(['role:manage']))
  ]
})

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

// .route('/', customRoute)

export default app;