import type { GetAllTeamsOutputDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';
import type { GetTeamsLeaderboardOutputDTO } from '@/lib/types/generated/GetTeamsLeaderboardOutputDTO';
import type { GetTeamDetailsOutputDTO } from '@/lib/types/generated/GetTeamDetailsOutputDTO';
import type { GetTeamMembersOutputDTO } from '@/lib/types/generated/GetTeamMembersOutputDTO';
import type { GetTeamJoinRequestsOutputDTO } from '@/lib/types/generated/GetTeamJoinRequestsOutputDTO';
import type { CreateTeamInputDTO } from '@/lib/types/generated/CreateTeamInputDTO';
import type { CreateTeamOutputDTO } from '@/lib/types/generated/CreateTeamOutputDTO';
import type { UpdateTeamInputDTO } from '@/lib/types/generated/UpdateTeamInputDTO';
import type { UpdateTeamOutputDTO } from '@/lib/types/generated/UpdateTeamOutputDTO';
import type { GetDriverTeamOutputDTO } from '@/lib/types/generated/GetDriverTeamOutputDTO';
import type { GetTeamMembershipOutputDTO } from '@/lib/types/generated/GetTeamMembershipOutputDTO';
import { BaseApiClient } from '../base/BaseApiClient';

/**
 * Teams API Client
 *
 * Handles all team-related API operations.
 */
export class TeamsApiClient extends BaseApiClient {
  /** Get all teams */
  getAll(): Promise<GetAllTeamsOutputDTO> {
    return this.get<GetAllTeamsOutputDTO>('/teams/all');
  }

  /** Get teams leaderboard */
  getLeaderboard(): Promise<GetTeamsLeaderboardOutputDTO> {
    return this.get<GetTeamsLeaderboardOutputDTO>('/teams/leaderboard');
  }

  /** Get team details */
  getDetails(teamId: string): Promise<GetTeamDetailsOutputDTO | null> {
    return this.get<GetTeamDetailsOutputDTO | null>(`/teams/${teamId}`);
  }

  /** Get team members */
  getMembers(teamId: string): Promise<GetTeamMembersOutputDTO> {
    return this.get<GetTeamMembersOutputDTO>(`/teams/${teamId}/members`);
  }

  /** Get team join requests */
  getJoinRequests(teamId: string): Promise<GetTeamJoinRequestsOutputDTO> {
    return this.get<GetTeamJoinRequestsOutputDTO>(`/teams/${teamId}/join-requests`);
  }

  /** Create a new team */
  create(input: CreateTeamInputDTO): Promise<CreateTeamOutputDTO> {
    return this.post<CreateTeamOutputDTO>('/teams', input);
  }

  /** Update team */
  update(teamId: string, input: UpdateTeamInputDTO): Promise<UpdateTeamOutputDTO> {
    return this.patch<UpdateTeamOutputDTO>(`/teams/${teamId}`, input);
  }

  /** Get driver's team */
  getDriverTeam(driverId: string): Promise<GetDriverTeamOutputDTO | null> {
    return this.get<GetDriverTeamOutputDTO | null>(`/teams/driver/${driverId}`);
  }

  /** Get membership for a driver in a team */
  getMembership(teamId: string, driverId: string): Promise<GetTeamMembershipOutputDTO | null> {
    return this.get<GetTeamMembershipOutputDTO | null>(`/teams/${teamId}/members/${driverId}`);
  }
}