import { Provider } from '@nestjs/common';
import { SponsorService } from './SponsorService';

// Import core interfaces
import { ISponsorRepository } from '@core/racing/domain/repositories/ISponsorRepository';
import { ISeasonSponsorshipRepository } from '@core/racing/domain/repositories/ISeasonSponsorshipRepository';
import { ISeasonRepository } from '@core/racing/domain/repositories/ISeasonRepository';
import { ILeagueRepository } from '@core/racing/domain/repositories/ILeagueRepository';
import { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
import { IRaceRepository } from '@core/racing/domain/repositories/IRaceRepository';
import { ISponsorshipPricingRepository } from '@core/racing/domain/repositories/ISponsorshipPricingRepository';
import { ISponsorshipRequestRepository } from '@core/racing/domain/repositories/ISponsorshipRequestRepository';
import type { Logger } from '@core/shared/application';

// Import use cases
import { GetSponsorshipPricingUseCase } from '@core/racing/application/use-cases/GetSponsorshipPricingUseCase';
import { GetSponsorsUseCase } from '@core/racing/application/use-cases/GetSponsorsUseCase';
import { CreateSponsorUseCase } from '@core/racing/application/use-cases/CreateSponsorUseCase';
import { GetSponsorDashboardUseCase } from '@core/racing/application/use-cases/GetSponsorDashboardUseCase';
import { GetSponsorSponsorshipsUseCase } from '@core/racing/application/use-cases/GetSponsorSponsorshipsUseCase';
import { GetEntitySponsorshipPricingUseCase } from '@core/racing/application/use-cases/GetEntitySponsorshipPricingUseCase';

// Import concrete in-memory implementations
import { InMemorySponsorRepository } from '@adapters/racing/persistence/inmemory/InMemorySponsorRepository';
import { InMemorySeasonSponsorshipRepository } from '@adapters/racing/persistence/inmemory/InMemorySeasonSponsorshipRepository';
import { InMemorySeasonRepository } from '@adapters/racing/persistence/inmemory/InMemorySeasonRepository';
import { InMemoryLeagueRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueRepository';
import { InMemoryLeagueMembershipRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueMembershipRepository';
import { InMemoryRaceRepository } from '@adapters/racing/persistence/inmemory/InMemoryRaceRepository';
import { InMemorySponsorshipPricingRepository } from '@adapters/racing/persistence/inmemory/InMemorySponsorshipPricingRepository';
import { InMemorySponsorshipRequestRepository } from '@adapters/racing/persistence/inmemory/InMemorySponsorshipRequestRepository';
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';

// Define injection tokens
export const SPONSOR_REPOSITORY_TOKEN = 'ISponsorRepository';
export const SEASON_SPONSORSHIP_REPOSITORY_TOKEN = 'ISeasonSponsorshipRepository';
export const SEASON_REPOSITORY_TOKEN = 'ISeasonRepository';
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
export const LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN = 'ILeagueMembershipRepository';
export const RACE_REPOSITORY_TOKEN = 'IRaceRepository';
export const SPONSORSHIP_PRICING_REPOSITORY_TOKEN = 'ISponsorshipPricingRepository';
export const SPONSORSHIP_REQUEST_REPOSITORY_TOKEN = 'ISponsorshipRequestRepository';
export const LOGGER_TOKEN = 'Logger';

// Use case tokens
export const GET_SPONSORSHIP_PRICING_USE_CASE_TOKEN = 'GetSponsorshipPricingUseCase';
export const GET_SPONSORS_USE_CASE_TOKEN = 'GetSponsorsUseCase';
export const CREATE_SPONSOR_USE_CASE_TOKEN = 'CreateSponsorUseCase';
export const GET_SPONSOR_DASHBOARD_USE_CASE_TOKEN = 'GetSponsorDashboardUseCase';
export const GET_SPONSOR_SPONSORSHIPS_USE_CASE_TOKEN = 'GetSponsorSponsorshipsUseCase';
export const GET_ENTITY_SPONSORSHIP_PRICING_USE_CASE_TOKEN = 'GetEntitySponsorshipPricingUseCase';

export const SponsorProviders: Provider[] = [
  SponsorService,
  // Repositories
  {
    provide: SPONSOR_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySponsorRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: SEASON_SPONSORSHIP_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySeasonSponsorshipRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: SEASON_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySeasonRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LEAGUE_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueMembershipRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: RACE_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryRaceRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: SPONSORSHIP_PRICING_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySponsorshipPricingRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: SPONSORSHIP_REQUEST_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySponsorshipRequestRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LOGGER_TOKEN,
    useClass: ConsoleLogger,
  },
  // Use cases
  {
    provide: GET_SPONSORSHIP_PRICING_USE_CASE_TOKEN,
    useFactory: () => new GetSponsorshipPricingUseCase(),
    inject: [],
  },
  {
    provide: GET_SPONSORS_USE_CASE_TOKEN,
    useFactory: (sponsorRepo: ISponsorRepository) => new GetSponsorsUseCase(sponsorRepo),
    inject: [SPONSOR_REPOSITORY_TOKEN],
  },
  {
    provide: CREATE_SPONSOR_USE_CASE_TOKEN,
    useFactory: (sponsorRepo: ISponsorRepository) => new CreateSponsorUseCase(sponsorRepo),
    inject: [SPONSOR_REPOSITORY_TOKEN],
  },
  {
    provide: GET_SPONSOR_DASHBOARD_USE_CASE_TOKEN,
    useFactory: (sponsorRepo: ISponsorRepository, seasonSponsorshipRepo: ISeasonSponsorshipRepository, seasonRepo: ISeasonRepository, leagueRepo: ILeagueRepository, leagueMembershipRepo: ILeagueMembershipRepository, raceRepo: IRaceRepository) =>
      new GetSponsorDashboardUseCase(sponsorRepo, seasonSponsorshipRepo, seasonRepo, leagueRepo, leagueMembershipRepo, raceRepo),
    inject: [SPONSOR_REPOSITORY_TOKEN, SEASON_SPONSORSHIP_REPOSITORY_TOKEN, SEASON_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN, LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, RACE_REPOSITORY_TOKEN],
  },
  {
    provide: GET_SPONSOR_SPONSORSHIPS_USE_CASE_TOKEN,
    useFactory: (sponsorRepo: ISponsorRepository, seasonSponsorshipRepo: ISeasonSponsorshipRepository, seasonRepo: ISeasonRepository, raceRepo: IRaceRepository) =>
      new GetSponsorSponsorshipsUseCase(sponsorRepo, seasonSponsorshipRepo, seasonRepo, raceRepo),
    inject: [SPONSOR_REPOSITORY_TOKEN, SEASON_SPONSORSHIP_REPOSITORY_TOKEN, SEASON_REPOSITORY_TOKEN, RACE_REPOSITORY_TOKEN],
  },
  {
    provide: GET_ENTITY_SPONSORSHIP_PRICING_USE_CASE_TOKEN,
    useFactory: (sponsorshipPricingRepo: ISponsorshipPricingRepository, sponsorshipRequestRepo: ISponsorshipRequestRepository, seasonSponsorshipRepo: ISeasonSponsorshipRepository, logger: Logger) =>
      new GetEntitySponsorshipPricingUseCase(sponsorshipPricingRepo, sponsorshipRequestRepo, seasonSponsorshipRepo, logger),
    inject: [SPONSORSHIP_PRICING_REPOSITORY_TOKEN, SPONSORSHIP_REQUEST_REPOSITORY_TOKEN, SEASON_SPONSORSHIP_REPOSITORY_TOKEN, LOGGER_TOKEN],
  },
];
