/**
 * Public Pricing Routes
 *
 * Public endpoints for retrieving current translation pricing
 */

import { Router, Request, Response } from 'express';
import { getTranslationPriceFromDatabase } from '../config';
import { logger } from '../utils/logger';

const router = Router();

/**
 * GET /v1/pricing
 * Get current translation pricing (public endpoint, no authentication required)
 *
 * Returns the current pricing per 1K characters
 */
router.get('/', async (_req: Request, res: Response) => {
  try {
    // Get current pricing from database (with .env fallback)
    const pricePerThousandCharacters = getTranslationPriceFromDatabase();

    logger.info('Pricing information requested', {
      pricePerThousandCharacters,
    });

    return res.status(200).json({
      pricing: {
        per_1k_characters: pricePerThousandCharacters,
      },
      currency: 'USD',
      timestamp: new Date().toISOString(),
    });
  } catch (error) {
    logger.error('Error retrieving pricing information', { error });

    return res.status(500).json({
      error: true,
      code: 'INTERNAL_ERROR',
      message: 'Failed to retrieve pricing information',
      timestamp: new Date().toISOString(),
    });
  }
});

export default router;
