import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import type { IRejectLeagueJoinRequestPresenter, RejectLeagueJoinRequestResultDTO, RejectLeagueJoinRequestViewModel } from '../presenters/IRejectLeagueJoinRequestPresenter';
import type { UseCase } from '@core/shared/application/UseCase';

export interface RejectLeagueJoinRequestUseCaseParams {
  requestId: string;
}

export interface RejectLeagueJoinRequestResultDTO {
  success: boolean;
  message: string;
}

export class RejectLeagueJoinRequestUseCase implements UseCase<RejectLeagueJoinRequestUseCaseParams, RejectLeagueJoinRequestResultDTO, RejectLeagueJoinRequestViewModel, IRejectLeagueJoinRequestPresenter> {
  constructor(private readonly leagueMembershipRepository: ILeagueMembershipRepository) {}

  async execute(params: RejectLeagueJoinRequestUseCaseParams, presenter: IRejectLeagueJoinRequestPresenter): Promise<void> {
    await this.leagueMembershipRepository.removeJoinRequest(params.requestId);
    const dto: RejectLeagueJoinRequestResultDTO = { success: true, message: 'Join request rejected.' };
    presenter.reset();
    presenter.present(dto);
  }
}