import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { DashboardStatsResult } from '../use-cases/GetDashboardStatsUseCase';

export interface DashboardStatsResponse {
  totalUsers: number;
  activeUsers: number;
  suspendedUsers: number;
  deletedUsers: number;
  systemAdmins: number;
  recentLogins: number;
  newUsersToday: number;
  userGrowth: {
    label: string;
    value: number;
    color: string;
  }[];
  roleDistribution: {
    label: string;
    value: number;
    color: string;
  }[];
  statusDistribution: {
    active: number;
    suspended: number;
    deleted: number;
  };
  activityTimeline: {
    date: string;
    newUsers: number;
    logins: number;
  }[];
}

export class DashboardStatsPresenter implements UseCaseOutputPort<DashboardStatsResult> {
  private _responseModel: DashboardStatsResponse | null = null;

  present(result: DashboardStatsResult): void {
    this._responseModel = {
      totalUsers: result.totalUsers,
      activeUsers: result.activeUsers,
      suspendedUsers: result.suspendedUsers,
      deletedUsers: result.deletedUsers,
      systemAdmins: result.systemAdmins,
      recentLogins: result.recentLogins,
      newUsersToday: result.newUsersToday,
      userGrowth: result.userGrowth,
      roleDistribution: result.roleDistribution,
      statusDistribution: result.statusDistribution,
      activityTimeline: result.activityTimeline,
    };
  }

  get responseModel(): DashboardStatsResponse {
    if (!this._responseModel) {
      throw new Error('No response model available. Call present() first.');
    }
    return this._responseModel;
  }

  reset(): void {
    this._responseModel = null;
  }
}