import type { UseCaseOutputPort } from '@core/shared/application';
import type { CreatePaymentResult } from '@core/payments/application/use-cases/CreatePaymentUseCase';
import type { CreatePaymentOutput } from '../dtos/PaymentsDto';

export class CreatePaymentPresenter implements UseCaseOutputPort<CreatePaymentResult> {
  private responseModel: CreatePaymentOutput | null = null;

  reset() {
    this.responseModel = null;
  }

  present(result: CreatePaymentResult): void {
    this.responseModel = {
      payment: {
        id: result.payment.id,
        type: result.payment.type,
        amount: result.payment.amount,
        platformFee: result.payment.platformFee,
        netAmount: result.payment.netAmount,
        payerId: result.payment.payerId,
        payerType: result.payment.payerType,
        leagueId: result.payment.leagueId,
        ...(result.payment.seasonId !== undefined ? { seasonId: result.payment.seasonId } : {}),
        status: result.payment.status,
        createdAt: result.payment.createdAt,
        ...(result.payment.completedAt !== undefined ? { completedAt: result.payment.completedAt } : {}),
      },
    };
  }

  getResponseModel(): CreatePaymentOutput {
    if (!this.responseModel) throw new Error('Presenter not presented');
    return this.responseModel;
  }
}