import { DashboardStatsPresenter } from './DashboardStatsPresenter';

describe('DashboardStatsPresenter', () => {
  let presenter: DashboardStatsPresenter;

  beforeEach(() => {
    presenter = new DashboardStatsPresenter();
  });

  describe('present', () => {
    it('should map result to response model', () => {
      const result = {
        totalUsers: 100,
        activeUsers: 80,
        suspendedUsers: 10,
        deletedUsers: 10,
        systemAdmins: 5,
        recentLogins: 20,
        newUsersToday: 5,
        userGrowth: [
          { label: 'Day 1', value: 10, color: '#000' },
          { label: 'Day 2', value: 15, color: '#000' },
        ],
        roleDistribution: [
          { label: 'Admin', value: 5, color: '#000' },
          { label: 'User', value: 95, color: '#000' },
        ],
        statusDistribution: {
          active: 80,
          suspended: 10,
          deleted: 10,
        },
        activityTimeline: [
          { date: '2024-01-01', newUsers: 5, logins: 20 },
        ],
      };

      presenter.present(result);

      expect(presenter.responseModel).toEqual({
        totalUsers: 100,
        activeUsers: 80,
        suspendedUsers: 10,
        deletedUsers: 10,
        systemAdmins: 5,
        recentLogins: 20,
        newUsersToday: 5,
        userGrowth: [
          { label: 'Day 1', value: 10, color: '#000' },
          { label: 'Day 2', value: 15, color: '#000' },
        ],
        roleDistribution: [
          { label: 'Admin', value: 5, color: '#000' },
          { label: 'User', value: 95, color: '#000' },
        ],
        statusDistribution: {
          active: 80,
          suspended: 10,
          deleted: 10,
        },
        activityTimeline: [
          { date: '2024-01-01', newUsers: 5, logins: 20 },
        ],
      });
    });

    it('should handle empty arrays', () => {
      const result = {
        totalUsers: 0,
        activeUsers: 0,
        suspendedUsers: 0,
        deletedUsers: 0,
        systemAdmins: 0,
        recentLogins: 0,
        newUsersToday: 0,
        userGrowth: [],
        roleDistribution: [],
        statusDistribution: {
          active: 0,
          suspended: 0,
          deleted: 0,
        },
        activityTimeline: [],
      };

      presenter.present(result);

      expect(presenter.responseModel.userGrowth).toEqual([]);
      expect(presenter.responseModel.roleDistribution).toEqual([]);
      expect(presenter.responseModel.activityTimeline).toEqual([]);
    });
  });

  describe('reset', () => {
    it('should clear the response model', () => {
      const result = {
        totalUsers: 100,
        activeUsers: 80,
        suspendedUsers: 10,
        deletedUsers: 10,
        systemAdmins: 5,
        recentLogins: 20,
        newUsersToday: 5,
        userGrowth: [],
        roleDistribution: [],
        statusDistribution: {
          active: 80,
          suspended: 10,
          deleted: 10,
        },
        activityTimeline: [],
      };

      presenter.present(result);
      expect(presenter.responseModel).toBeDefined();

      presenter.reset();
      expect(() => presenter.responseModel).toThrow('No response model available. Call present() first.');
    });
  });

  describe('responseModel', () => {
    it('should throw error when accessed before present()', () => {
      expect(() => presenter.responseModel).toThrow('No response model available. Call present() first.');
    });
  });
});