import type { LeaguesApiClient } from '../../api/leagues/LeaguesApiClient';
import type { LeagueMemberViewModel } from '../../view-models';
import type { LeagueMembersPresenter } from '../../presenters/LeagueMembersPresenter';

/**
 * League Membership Service
 *
 * Orchestrates league membership operations by coordinating API calls and presentation logic.
 * All dependencies are injected via constructor.
 */
export class LeagueMembershipService {
  constructor(
    private readonly apiClient: LeaguesApiClient,
    private readonly leagueMembersPresenter: LeagueMembersPresenter
  ) {}

  /**
   * Get league memberships with presentation transformation
   */
  async getLeagueMemberships(leagueId: string, currentUserId: string): Promise<LeagueMemberViewModel[]> {
    const dto = await this.apiClient.getMemberships(leagueId);
    return this.leagueMembersPresenter.present(dto, currentUserId);
  }

  /**
   * Remove a member from league
   */
  async removeMember(leagueId: string, performerDriverId: string, targetDriverId: string): Promise<{ success: boolean }> {
    return await this.apiClient.removeMember(leagueId, performerDriverId, targetDriverId);
  }
}