/**
 * @ai-summary Fastify routes for user preferences API
 * @ai-context Route definitions for unit system, currency, and timezone preferences
 */

import { FastifyInstance, FastifyPluginOptions } from 'fastify';
import { FastifyPluginAsync } from 'fastify';
import { UserPreferencesController } from './user-preferences.controller';
import { UpdateUserPreferencesRequest } from '../../../core/user-preferences/user-preferences.types';

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

  // GET /api/user/preferences - Get user preferences (creates defaults if none)
  fastify.get('/user/preferences', {
    preHandler: [fastify.authenticate],
    handler: controller.getPreferences.bind(controller),
  });

  // PUT /api/user/preferences - Update user preferences
  fastify.put<{ Body: UpdateUserPreferencesRequest }>('/user/preferences', {
    preHandler: [fastify.authenticate],
    handler: controller.updatePreferences.bind(controller),
  });
};
