import type { UseCaseOutputPort } from '@core/shared/application';
import type { UpdatePaymentStatusResult } from '@core/payments/application/use-cases/UpdatePaymentStatusUseCase';
import type { UpdatePaymentStatusOutput } from '../dtos/PaymentsDto';

export class UpdatePaymentStatusPresenter implements UseCaseOutputPort<UpdatePaymentStatusResult> {
  private responseModel: UpdatePaymentStatusOutput | null = null;

  reset() {
    this.responseModel = null;
  }

  present(result: UpdatePaymentStatusResult): 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(): UpdatePaymentStatusOutput {
    if (!this.responseModel) throw new Error('Presenter not presented');
    return this.responseModel;
  }
}