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 '@d8d/shared-types';

import { createCrudRoutes } from '@d8d/shared-crud';
import { File } from '../entities/file.entity';
import { FileSchema, CreateFileDto, UpdateFileDto } from '../schemas/file.schema';
import { authMiddleware } from '@d8d/auth-module/middleware';

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


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

export { fileRoutes };
export default fileRoutes;