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

// Import core interfaces
import type { Logger } from '@core/shared/application/Logger';

// Import concrete in-memory implementations
import { InMemoryLeagueRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueRepository';
import { InMemoryLeagueMembershipRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueMembershipRepository';
import { InMemoryLeagueStandingsRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueStandingsRepository';
import { InMemorySeasonRepository } from '@adapters/racing/persistence/inmemory/InMemorySeasonRepository';
import { InMemoryLeagueScoringConfigRepository } from '@adapters/racing/persistence/inmemory/InMemoryLeagueScoringConfigRepository';
import { InMemoryGameRepository } from '@adapters/racing/persistence/inmemory/InMemoryGameRepository';
import { InMemoryProtestRepository } from '@adapters/racing/persistence/inmemory/InMemoryProtestRepository';
import { InMemoryRaceRepository } from '@adapters/racing/persistence/inmemory/InMemoryRaceRepository';
import { InMemoryDriverRepository } from '@adapters/racing/persistence/inmemory/InMemoryDriverRepository';
import { InMemoryStandingRepository } from '@adapters/racing/persistence/inmemory/InMemoryStandingRepository';
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';

// Import use cases
import { GetAllLeaguesWithCapacityUseCase } from '@core/racing/application/use-cases/GetAllLeaguesWithCapacityUseCase';
import { GetLeagueStandingsUseCase } from '@core/racing/application/use-cases/GetLeagueStandingsUseCase';
import { GetLeagueFullConfigUseCase } from '@core/racing/application/use-cases/GetLeagueFullConfigUseCase';
import { CreateLeagueWithSeasonAndScoringUseCase } from '@core/racing/application/use-cases/CreateLeagueWithSeasonAndScoringUseCase';
import { GetRaceProtestsUseCase } from '@core/racing/application/use-cases/GetRaceProtestsUseCase';
import { GetTotalLeaguesUseCase } from '@core/racing/application/use-cases/GetTotalLeaguesUseCase';
import { GetLeagueJoinRequestsUseCase } from '@core/racing/application/use-cases/GetLeagueJoinRequestsUseCase';
import { ApproveLeagueJoinRequestUseCase } from '@core/racing/application/use-cases/ApproveLeagueJoinRequestUseCase';
import { RejectLeagueJoinRequestUseCase } from '@core/racing/application/use-cases/RejectLeagueJoinRequestUseCase';
import { RemoveLeagueMemberUseCase } from '@core/racing/application/use-cases/RemoveLeagueMemberUseCase';
import { UpdateLeagueMemberRoleUseCase } from '@core/racing/application/use-cases/UpdateLeagueMemberRoleUseCase';
import { GetLeagueOwnerSummaryUseCase } from '@core/racing/application/use-cases/GetLeagueOwnerSummaryUseCase';
import { GetLeagueProtestsUseCase } from '@core/racing/application/use-cases/GetLeagueProtestsUseCase';
import { GetLeagueSeasonsUseCase } from '@core/racing/application/use-cases/GetLeagueSeasonsUseCase';
import { GetLeagueMembershipsUseCase } from '@core/racing/application/use-cases/GetLeagueMembershipsUseCase';
import { GetLeagueScheduleUseCase } from '@core/racing/application/use-cases/GetLeagueScheduleUseCase';
import { GetLeagueStatsUseCase } from '@core/racing/application/use-cases/GetLeagueStatsUseCase';
import { GetLeagueAdminPermissionsUseCase } from '@core/racing/application/use-cases/GetLeagueAdminPermissionsUseCase';

// Define injection tokens
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
export const LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN = 'ILeagueMembershipRepository';
export const LEAGUE_STANDINGS_REPOSITORY_TOKEN = 'ILeagueStandingsRepository';
export const STANDING_REPOSITORY_TOKEN = 'IStandingRepository';
export const SEASON_REPOSITORY_TOKEN = 'ISeasonRepository';
export const LEAGUE_SCORING_CONFIG_REPOSITORY_TOKEN = 'ILeagueScoringConfigRepository';
export const GAME_REPOSITORY_TOKEN = 'IGameRepository';
export const PROTEST_REPOSITORY_TOKEN = 'IProtestRepository';
export const RACE_REPOSITORY_TOKEN = 'IRaceRepository';
export const DRIVER_REPOSITORY_TOKEN = 'IDriverRepository';
export const LOGGER_TOKEN = 'Logger'; // Already defined in AuthProviders, but good to have here too

export const LeagueProviders: Provider[] = [
  LeagueService, // Provide the service itself
  {
    provide: LEAGUE_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueRepository(logger), // Factory for InMemoryLeagueRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueMembershipRepository(logger), // Factory for InMemoryLeagueMembershipRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LEAGUE_STANDINGS_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueStandingsRepository(logger), // Factory for InMemoryLeagueStandingsRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: STANDING_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryStandingRepository(logger), // Factory for InMemoryStandingRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: SEASON_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemorySeasonRepository(logger), // Factory for InMemorySeasonRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LEAGUE_SCORING_CONFIG_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryLeagueScoringConfigRepository(logger), // Factory for InMemoryLeagueScoringConfigRepository
    inject: [LOGGER_TOKEN],
  },
  {
    provide: GAME_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryGameRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: PROTEST_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryProtestRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: RACE_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryRaceRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: DRIVER_REPOSITORY_TOKEN,
    useFactory: (logger: Logger) => new InMemoryDriverRepository(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: LOGGER_TOKEN,
    useClass: ConsoleLogger,
  },
  // Use cases
  GetAllLeaguesWithCapacityUseCase,
  GetLeagueStandingsUseCase,
  GetLeagueStatsUseCase,
  GetLeagueFullConfigUseCase,
  CreateLeagueWithSeasonAndScoringUseCase,
  GetRaceProtestsUseCase,
  GetTotalLeaguesUseCase,
  GetLeagueJoinRequestsUseCase,
  ApproveLeagueJoinRequestUseCase,
  RejectLeagueJoinRequestUseCase,
  RemoveLeagueMemberUseCase,
  UpdateLeagueMemberRoleUseCase,
  GetLeagueOwnerSummaryUseCase,
  GetLeagueProtestsUseCase,
  GetLeagueSeasonsUseCase,
  GetLeagueMembershipsUseCase,
  GetLeagueScheduleUseCase,
  GetLeagueStatsUseCase,
  GetLeagueAdminPermissionsUseCase,
];
