import type { GetTeamJoinRequestsResult } from '@core/racing/application/use-cases/GetTeamJoinRequestsUseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { GetTeamJoinRequestsOutputDTO } from '../dtos/GetTeamJoinRequestsOutputDTO';

export class TeamJoinRequestsPresenter implements UseCaseOutputPort<GetTeamJoinRequestsResult> {
  private result: GetTeamJoinRequestsOutputDTO | null = null;

  reset() {
    this.result = null;
  }

  present(result: GetTeamJoinRequestsResult): void {
    this.result = {
      requests: result.joinRequests.map(request => ({
        requestId: request.id,
        driverId: request.driverId,
        driverName: request.driver.name.toString(),
        teamId: request.teamId,
        status: 'pending',
        requestedAt: request.requestedAt.toISOString(),
        avatarUrl: '', // TODO: get avatar
      })),
      pendingCount: result.joinRequests.length,
      totalCount: result.joinRequests.length,
    };
  }

  getResponseModel(): GetTeamJoinRequestsOutputDTO | null {
    return this.result;
  }
}