import { BaseApiClient } from '../base/BaseApiClient';
import type { CreateSponsorInputDTO } from '../../types/generated/CreateSponsorInputDTO';
import type { SponsorDashboardDTO } from '../../types/generated/SponsorDashboardDTO';
import type { SponsorSponsorshipsDTO } from '../../types/generated/SponsorSponsorshipsDTO';
import type { GetPendingSponsorshipRequestsOutputDTO } from '../../types/generated/GetPendingSponsorshipRequestsOutputDTO';
import type { AcceptSponsorshipRequestInputDTO } from '../../types/generated/AcceptSponsorshipRequestInputDTO';
import type { RejectSponsorshipRequestInputDTO } from '../../types/generated/RejectSponsorshipRequestInputDTO';
import type { GetSponsorOutputDTO } from '../../types/generated/GetSponsorOutputDTO';
import type { SponsorDTO } from '../../types/generated/SponsorDTO';

// Types that are not yet generated
export type CreateSponsorOutputDto = { id: string; name: string };
export type GetEntitySponsorshipPricingResultDto = { pricing: Array<{ entityType: string; price: number }> };
export type GetSponsorsOutputDto = { sponsors: SponsorDTO[] };

/**
 * Sponsors API Client
 *
 * Handles all sponsor-related API operations.
 */
export class SponsorsApiClient extends BaseApiClient {
  /** Get sponsorship pricing */
  getPricing(): Promise<GetEntitySponsorshipPricingResultDto> {
    return this.get<GetEntitySponsorshipPricingResultDto>('/sponsors/pricing');
  }

  /** Get all sponsors */
  getAll(): Promise<GetSponsorsOutputDto> {
    return this.get<GetSponsorsOutputDto>('/sponsors');
  }

  /** Create a new sponsor */
  create(input: CreateSponsorInputDTO): Promise<CreateSponsorOutputDto> {
    return this.post<CreateSponsorOutputDto>('/sponsors', input);
  }

  /** Get sponsor dashboard */
  getDashboard(sponsorId: string): Promise<SponsorDashboardDTO | null> {
    return this.get<SponsorDashboardDTO | null>(`/sponsors/dashboard/${sponsorId}`);
  }

  /** Get sponsor sponsorships */
  getSponsorships(sponsorId: string): Promise<SponsorSponsorshipsDTO | null> {
    return this.get<SponsorSponsorshipsDTO | null>(`/sponsors/${sponsorId}/sponsorships`);
  }

  /** Get sponsor by ID */
  getSponsor(sponsorId: string): Promise<GetSponsorOutputDTO | null> {
    return this.get<GetSponsorOutputDTO | null>(`/sponsors/${sponsorId}`);
  }

  /** Get pending sponsorship requests for an entity */
  getPendingSponsorshipRequests(params: { entityType: string; entityId: string }): Promise<GetPendingSponsorshipRequestsOutputDTO> {
    return this.get<GetPendingSponsorshipRequestsOutputDTO>(`/sponsors/requests?entityType=${params.entityType}&entityId=${params.entityId}`);
  }

  /** Accept a sponsorship request */
  acceptSponsorshipRequest(requestId: string, input: AcceptSponsorshipRequestInputDTO): Promise<void> {
    return this.post(`/sponsors/requests/${requestId}/accept`, input);
  }

  /** Reject a sponsorship request */
  rejectSponsorshipRequest(requestId: string, input: RejectSponsorshipRequestInputDTO): Promise<void> {
    return this.post(`/sponsors/requests/${requestId}/reject`, input);
  }

  /** Get sponsor billing information */
  getBilling(sponsorId: string): Promise<{
    paymentMethods: any[];
    invoices: any[];
    stats: any;
  }> {
    return this.get(`/sponsors/billing/${sponsorId}`);
  }

  /** Get available leagues for sponsorship */
  getAvailableLeagues(): Promise<any[]> {
    return this.get('/sponsors/leagues/available');
  }

  /** Get detailed league information */
  getLeagueDetail(leagueId: string): Promise<{
    league: any;
    drivers: any[];
    races: any[];
  }> {
    return this.get(`/sponsors/leagues/${leagueId}/detail`);
  }

  /** Get sponsor settings */
  getSettings(sponsorId: string): Promise<{
    profile: any;
    notifications: any;
    privacy: any;
  }> {
    return this.get(`/sponsors/settings/${sponsorId}`);
  }

  /** Update sponsor settings */
  updateSettings(sponsorId: string, input: any): Promise<void> {
    return this.put(`/sponsors/settings/${sponsorId}`, input);
  }
}