import { Request, Response, NextFunction } from 'express';
import { GetNetworksListUseCase } from '../../application/use-cases/network/get-networks-list.use-case';
import { GetNetworkGasInfoUseCase } from '../../application/use-cases/network/get-network-gas-info.use-case';

export class NetworkController {
  constructor(
    private readonly getNetworksListUseCase: GetNetworksListUseCase,
    private readonly getNetworkGasInfoUseCase: GetNetworkGasInfoUseCase,
  ) {}

  getAll = async (_req: Request, res: Response, next: NextFunction): Promise<void> => {
    try {
      const networks = await this.getNetworksListUseCase.execute();
      res.status(200).json({ success: true, data: networks });
    } catch (error) {
      next(error);
    }
  };

  getGasInfo = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
    try {
      const gasInfo = await this.getNetworkGasInfoUseCase.execute(req.params.networkId as string);
      res.status(200).json({ success: true, data: gasInfo });
    } catch (error) {
      next(error);
    }
  };
}
