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

// Import core interfaces
import { DriverRepository } from '@core/racing/domain/repositories/DriverRepository';
import { LeagueMembershipRepository } from '@core/racing/domain/repositories/LeagueMembershipRepository';
import { LeagueRepository } from '@core/racing/domain/repositories/LeagueRepository';
import { RaceRegistrationRepository } from '@core/racing/domain/repositories/RaceRegistrationRepository';
import { RaceRepository } from '@core/racing/domain/repositories/RaceRepository';
import { ResultRepository } from '@core/racing/domain/repositories/ResultRepository';
import { StandingRepository } from '@core/racing/domain/repositories/StandingRepository';
import type { Logger } from '@core/shared/domain/Logger';
import { FeedRepository } from '@core/social/domain/repositories/FeedRepository';
import { SocialGraphRepository } from '@core/social/domain/repositories/SocialGraphRepository';

import { ImageServicePort } from '@core/media/application/ports/ImageServicePort';
import { DashboardOverviewUseCase } from '@core/racing/application/use-cases/DashboardOverviewUseCase';
import { SOCIAL_FEED_REPOSITORY_TOKEN, SOCIAL_GRAPH_REPOSITORY_TOKEN } from '../../persistence/social/SocialPersistenceTokens';

// Import concrete implementations
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';
import { InMemoryImageServiceAdapter } from '@adapters/media/ports/InMemoryImageServiceAdapter';
import {
    DASHBOARD_OVERVIEW_USE_CASE_TOKEN,
    DRIVER_REPOSITORY_TOKEN,
    IMAGE_SERVICE_TOKEN,
    LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
    LEAGUE_REPOSITORY_TOKEN,
    LOGGER_TOKEN,
    RACE_REGISTRATION_REPOSITORY_TOKEN,
    RACE_REPOSITORY_TOKEN,
    RESULT_REPOSITORY_TOKEN,
    STANDING_REPOSITORY_TOKEN,
} from './DashboardTokens';
import { DashboardOverviewPresenter } from './presenters/DashboardOverviewPresenter';

// Re-export tokens for convenience (legacy imports)
export {
    DASHBOARD_OVERVIEW_USE_CASE_TOKEN,
    DRIVER_REPOSITORY_TOKEN,
    IMAGE_SERVICE_TOKEN,
    LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
    LEAGUE_REPOSITORY_TOKEN,
    LOGGER_TOKEN,
    RACE_REGISTRATION_REPOSITORY_TOKEN,
    RACE_REPOSITORY_TOKEN,
    RESULT_REPOSITORY_TOKEN,
    STANDING_REPOSITORY_TOKEN
} from './DashboardTokens';

export const DashboardProviders: Provider[] = [
  DashboardOverviewPresenter,
  {
    provide: LOGGER_TOKEN,
    useClass: ConsoleLogger,
  },
  {
    provide: IMAGE_SERVICE_TOKEN,
    useFactory: (logger: Logger) => new InMemoryImageServiceAdapter(logger),
    inject: [LOGGER_TOKEN],
  },
  {
    provide: DASHBOARD_OVERVIEW_USE_CASE_TOKEN,
    useFactory: (
      driverRepo: DriverRepository,
      raceRepo: RaceRepository,
      resultRepo: ResultRepository,
      leagueRepo: LeagueRepository,
      standingRepo: StandingRepository,
      membershipRepo: LeagueMembershipRepository,
      registrationRepo: RaceRegistrationRepository,
      feedRepo: FeedRepository,
      socialRepo: SocialGraphRepository,
      imageService: ImageServicePort,
    ) =>
      new DashboardOverviewUseCase(
        driverRepo,
        raceRepo,
        resultRepo,
        leagueRepo,
        standingRepo,
        membershipRepo,
        registrationRepo,
        feedRepo,
        socialRepo,
        async (driverId: string) => imageService.getDriverAvatar(driverId),
        () => null,
      ),
    inject: [
      DRIVER_REPOSITORY_TOKEN,
      RACE_REPOSITORY_TOKEN,
      RESULT_REPOSITORY_TOKEN,
      LEAGUE_REPOSITORY_TOKEN,
      STANDING_REPOSITORY_TOKEN,
      LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
      RACE_REGISTRATION_REPOSITORY_TOKEN,
      SOCIAL_FEED_REPOSITORY_TOKEN,
      SOCIAL_GRAPH_REPOSITORY_TOKEN,
      IMAGE_SERVICE_TOKEN,
    ],
  },
];
