import type { Logger, UseCaseOutputPort, UseCase } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';

export interface GetDashboardDataInput {}

export interface GetDashboardDataOutput {
  totalUsers: number;
  activeUsers: number;
  totalRaces: number;
  totalLeagues: number;
}

export type GetDashboardDataErrorCode = 'REPOSITORY_ERROR';

export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, void, GetDashboardDataErrorCode> {
  constructor(
    private readonly logger: Logger,
    private readonly output: UseCaseOutputPort<GetDashboardDataOutput>,
  ) {}

  async execute(): Promise<Result<void, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>> {
    try {
      // Placeholder implementation - would need repositories from identity and racing domains
      const totalUsers = 0;
      const activeUsers = 0;
      const totalRaces = 0;
      const totalLeagues = 0;

      const resultModel: GetDashboardDataOutput = {
        totalUsers,
        activeUsers,
        totalRaces,
        totalLeagues,
      };

      this.output.present(resultModel);

      this.logger.info('Dashboard data retrieved', {
        totalUsers,
        activeUsers,
        totalRaces,
        totalLeagues,
      });

      return Result.ok(undefined);
    } catch (error) {
      const err = error as Error;
      this.logger.error('Failed to get dashboard data', err);
      return Result.err({
        code: 'REPOSITORY_ERROR',
        details: { message: err.message ?? 'Failed to get dashboard data' },
      });
    }
  }
}