import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
import { OpenAPIHono } from '@hono/zod-openapi';
import { StockData } from '@/server/modules/stock/stock-data.entity';
import { StockDataSchema, CreateStockDataDto, UpdateStockDataDto } from '@/server/modules/stock/stock-data.schema';
import { authMiddleware } from '@/server/middleware/auth.middleware';
import getStockHistoryRoute from './history/[code]/get';

// 基础CRUD路由
const stockDataRoutes = createCrudRoutes({
  entity: StockData,
  createSchema: CreateStockDataDto,
  updateSchema: UpdateStockDataDto,
  getSchema: StockDataSchema,
  listSchema: StockDataSchema,
  searchFields: ['code'],
  middleware: [authMiddleware]
});

const app = new OpenAPIHono()
  .route('/', stockDataRoutes)
  .route('/history', getStockHistoryRoute);

export default app;