import { Request, Response } from 'express';
import { GetAllProtocolsUseCase } from '../../../application/usecases/GetAllProtocolsUseCase';
import { GetProtocolByIdUseCase } from '../../../application/usecases/GetProtocolByIdUseCase';

export class ProtocolController {
  constructor(
    private getAllProtocolsUseCase: GetAllProtocolsUseCase,
    private getProtocolByIdUseCase: GetProtocolByIdUseCase
  ) {}

  getAll = async (_req: Request, res: Response): Promise<void> => {
    try {
      const protocols = await this.getAllProtocolsUseCase.execute();
      res.json({
        message: 'Telephone protocols list',
        data: protocols
      });
    } catch (error) {
      res.status(500).json({ message: 'Internal server error' });
    }
  };

  getById = async (req: Request, res: Response): Promise<void> => {
    try {
      const protocol = await this.getProtocolByIdUseCase.execute(req.params.id);
      if (protocol) {
        res.json({
          message: 'Protocol found',
          data: protocol
        });
      } else {
        res.status(404).json({
          message: 'Protocol not found',
          id: req.params.id
        });
      }
    } catch (error) {
      res.status(500).json({ message: 'Internal server error' });
    }
  };
}
