/**
 * @ai-summary Fastify routes for ownership costs API
 * @ai-context Route definitions with Fastify plugin pattern and authentication
 */

import { FastifyInstance, FastifyPluginOptions } from 'fastify';
import { FastifyPluginAsync } from 'fastify';
import { OwnershipCostsController } from './ownership-costs.controller';

export const ownershipCostsRoutes: FastifyPluginAsync = async (
  fastify: FastifyInstance,
  _opts: FastifyPluginOptions
) => {
  const controller = new OwnershipCostsController();

  // POST /api/ownership-costs - Create new ownership cost
  fastify.post('/ownership-costs', {
    preHandler: [fastify.authenticate],
    handler: controller.create.bind(controller)
  });

  // GET /api/ownership-costs/:id - Get specific ownership cost
  fastify.get('/ownership-costs/:id', {
    preHandler: [fastify.authenticate],
    handler: controller.getById.bind(controller)
  });

  // PUT /api/ownership-costs/:id - Update ownership cost
  fastify.put('/ownership-costs/:id', {
    preHandler: [fastify.authenticate],
    handler: controller.update.bind(controller)
  });

  // DELETE /api/ownership-costs/:id - Delete ownership cost
  fastify.delete('/ownership-costs/:id', {
    preHandler: [fastify.authenticate],
    handler: controller.delete.bind(controller)
  });

  // GET /api/ownership-costs/vehicle/:vehicleId - Get costs for a vehicle
  fastify.get('/ownership-costs/vehicle/:vehicleId', {
    preHandler: [fastify.authenticate],
    handler: controller.getByVehicle.bind(controller)
  });

  // GET /api/ownership-costs/vehicle/:vehicleId/stats - Get aggregated cost stats
  fastify.get('/ownership-costs/vehicle/:vehicleId/stats', {
    preHandler: [fastify.authenticate],
    handler: controller.getVehicleStats.bind(controller)
  });
};

// For backward compatibility during migration
export function registerOwnershipCostsRoutes() {
  throw new Error('registerOwnershipCostsRoutes is deprecated - use ownershipCostsRoutes Fastify plugin instead');
}
