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

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

const fileCrudRoutes = createCrudRoutes({
  entity: FileMt,
  createSchema: CreateFileDto,
  updateSchema: UpdateFileDto,
  getSchema: FileSchema,
  listSchema: FileSchema,
  searchFields: ['name', 'type', 'description'],
  relations: ['uploadUser'],
  middleware: [authMiddleware],
  tenantOptions: {
    enabled: true,
    tenantIdField: 'tenantId',
    autoExtractFromContext: true
  }
})


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

export { fileRoutesMt };
export default fileRoutesMt;