/**
 * @ai-summary Platform feature routes
 * @ai-context Fastify route registration with validation
 */
import { FastifyInstance } from 'fastify';
import fastifyPlugin from 'fastify-plugin';
import { PlatformController } from './platform.controller';
import {
  MakesQuery,
  ModelsQuery,
  TrimsQuery,
  EnginesQuery,
  TransmissionsQuery
} from '../models/requests';
import pool from '../../../core/config/database';

async function platformRoutes(fastify: FastifyInstance) {
  const controller = new PlatformController(pool);

  fastify.get('/platform/years', {
    preHandler: [fastify.authenticate]
  }, controller.getYears.bind(controller));

  fastify.get<{ Querystring: MakesQuery }>('/platform/makes', {
    preHandler: [fastify.authenticate]
  }, controller.getMakes.bind(controller));

  fastify.get<{ Querystring: ModelsQuery }>('/platform/models', {
    preHandler: [fastify.authenticate]
  }, controller.getModels.bind(controller));

  fastify.get<{ Querystring: TrimsQuery }>('/platform/trims', {
    preHandler: [fastify.authenticate]
  }, controller.getTrims.bind(controller));

  fastify.get<{ Querystring: EnginesQuery }>('/platform/engines', {
    preHandler: [fastify.authenticate]
  }, controller.getEngines.bind(controller));

  fastify.get<{ Querystring: TransmissionsQuery }>('/platform/transmissions', {
    preHandler: [fastify.authenticate]
  }, controller.getTransmissions.bind(controller));
}

export default fastifyPlugin(platformRoutes);
export { platformRoutes };
