import type { Request, Response, NextFunction } from 'express';
import * as planService from '../services/plan-catalogo.service.js';

export async function getPlans(req: Request, res: Response, next: NextFunction) {
  try {
    const vertical = req.query.vertical as string | undefined;
    const plans = await planService.listPlans(vertical);
    return res.json({ data: plans });
  } catch (err) { return next(err); }
}

export async function getAddons(req: Request, res: Response, next: NextFunction) {
  try {
    const vertical = req.query.vertical as string | undefined;
    const addons = await planService.listAddons(vertical);
    return res.json({ data: addons });
  } catch (err) { return next(err); }
}

export async function getPlan(req: Request, res: Response, next: NextFunction) {
  try {
    const plan = await planService.getPlanByCodename(String(req.params.codename));
    if (!plan) return res.status(404).json({ message: 'Plan no encontrado' });
    return res.json(plan);
  } catch (err) { return next(err); }
}
