import { BaseApiClient } from '../base/BaseApiClient';
import type {
  AllTeamsDto,
  TeamDetailsDto,
  TeamMembersDto,
  TeamJoinRequestsDto,
  CreateTeamInputDto,
  CreateTeamOutputDto,
  UpdateTeamInputDto,
  UpdateTeamOutputDto,
  DriverTeamDto,
} from '../../dtos';

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

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

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

  /** Get team join requests */
  getJoinRequests(teamId: string): Promise<TeamJoinRequestsDto> {
    return this.get<TeamJoinRequestsDto>(`/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<DriverTeamDto | null> {
    return this.get<DriverTeamDto | null>(`/teams/driver/${driverId}`);
  }
}