import { OpenAPIHono } from '@hono/zod-openapi';
import uploadPolicyRoute from './upload-policy/post';
import multipartPolicyRoute from './multipart-policy/post';
import completeMultipartRoute from './multipart-complete/post';
import getUrlRoute from './[id]/get-url';
import deleteRoute from './[id]/delete';
import downloadRoute from './[id]/download';
import { AuthContext } from '@/server/types/context';

import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
import { File } from '@/server/modules/files/file.entity';
import { FileSchema, CreateFileDto, UpdateFileDto } from '@/server/modules/files/file.schema';
import { authMiddleware } from '@/server/middleware/auth.middleware';

const fileRoutes = createCrudRoutes({
  entity: File,
  createSchema: CreateFileDto,
  updateSchema: UpdateFileDto,
  getSchema: FileSchema,
  listSchema: FileSchema,
  searchFields: ['name', 'type', 'description'],
  relations: ['uploadUser'],
  middleware: [authMiddleware]
})


// 创建路由实例并聚合所有子路由
const app = new OpenAPIHono<AuthContext>()
.route('/upload-policy', uploadPolicyRoute)
.route('/multipart-policy', multipartPolicyRoute)
.route('/multipart-complete', completeMultipartRoute)
.route('/', getUrlRoute)
.route('/', downloadRoute)
.route('/', deleteRoute)
.route('/', fileRoutes)

export default app;