import {
  UserStatus,
  UserStatusValues,
  UserRoles,
  UserRoleHeirarchy,
} from './userStatus.js';

describe('User Status Constants', () => {
  describe('UserStatus object', () => {
    test('is defined', () => {
      expect(UserStatus).toBeDefined();
      expect(typeof UserStatus).toBe('object');
    });

    test('has Active property with value 22', () => {
      expect(UserStatus.Active).toBe(22);
    });

    test('has Deleted property with value 24', () => {
      expect(UserStatus.Deleted).toBe(24);
    });

    test('has Deactive property with value 23', () => {
      expect(UserStatus.Deactive).toBe(23);
    });

    test('only has three properties', () => {
      expect(Object.keys(UserStatus)).toHaveLength(3);
    });
  });

  describe('UserStatusValues array', () => {
    test('is defined and is an array', () => {
      expect(UserStatusValues).toBeDefined();
      expect(Array.isArray(UserStatusValues)).toBe(true);
    });

    test('has three elements', () => {
      expect(UserStatusValues).toHaveLength(3);
    });

    test('contains Active status', () => {
      const activeStatus = UserStatusValues.find((s) => s.key === 22);
      expect(activeStatus).toBeDefined();
      expect(activeStatus.value).toBe('Active');
    });

    test('contains Deleted status', () => {
      const deletedStatus = UserStatusValues.find((s) => s.key === 24);
      expect(deletedStatus).toBeDefined();
      expect(deletedStatus.value).toBe('Deleted');
    });

    test('contains Deactive status', () => {
      const deactiveStatus = UserStatusValues.find((s) => s.key === 23);
      expect(deactiveStatus).toBeDefined();
      expect(deactiveStatus.value).toBe('Deactive');
    });

    test('all elements have key and value properties', () => {
      UserStatusValues.forEach((status) => {
        expect(status).toHaveProperty('key');
        expect(status).toHaveProperty('value');
        expect(typeof status.key).toBe('number');
        expect(typeof status.value).toBe('string');
      });
    });
  });

  describe('UserRoles array', () => {
    test('is defined and is an array', () => {
      expect(UserRoles).toBeDefined();
      expect(Array.isArray(UserRoles)).toBe(true);
    });

    test('has four elements', () => {
      expect(UserRoles).toHaveLength(4);
    });

    test('contains Admin role', () => {
      const adminRole = UserRoles.find((r) => r.key === 21);
      expect(adminRole).toBeDefined();
      expect(adminRole.value).toBe('Admin');
    });

    test('contains Super Admin role', () => {
      const superAdminRole = UserRoles.find((r) => r.key === 20);
      expect(superAdminRole).toBeDefined();
      expect(superAdminRole.value).toBe('Super Admin');
    });

    test('contains System Admin role', () => {
      const systemAdminRole = UserRoles.find((r) => r.key === 26);
      expect(systemAdminRole).toBeDefined();
      expect(systemAdminRole.value).toBe('System Admin');
    });

    test('contains User role', () => {
      const userRole = UserRoles.find((r) => r.key === 25);
      expect(userRole).toBeDefined();
      expect(userRole.value).toBe('User');
    });

    test('all elements have key and value properties', () => {
      UserRoles.forEach((role) => {
        expect(role).toHaveProperty('key');
        expect(role).toHaveProperty('value');
        expect(typeof role.key).toBe('number');
        expect(typeof role.value).toBe('string');
      });
    });

    test('all role keys are unique', () => {
      const keys = UserRoles.map((r) => r.key);
      const uniqueKeys = [...new Set(keys)];
      expect(keys).toHaveLength(uniqueKeys.length);
    });
  });

  describe('UserRoleHeirarchy array', () => {
    test('is defined and is an array', () => {
      expect(UserRoleHeirarchy).toBeDefined();
      expect(Array.isArray(UserRoleHeirarchy)).toBe(true);
    });

    test('has three elements', () => {
      expect(UserRoleHeirarchy).toHaveLength(3);
    });

    test('contains Full View', () => {
      const fullView = UserRoleHeirarchy.find((h) => h.key === 1);
      expect(fullView).toBeDefined();
      expect(fullView.value).toBe('Full View');
    });

    test('contains Hierarchical View', () => {
      const hierarchicalView = UserRoleHeirarchy.find((h) => h.key === 2);
      expect(hierarchicalView).toBeDefined();
      expect(hierarchicalView.value).toBe('Hierarchical View');
    });

    test('contains Individual View', () => {
      const individualView = UserRoleHeirarchy.find((h) => h.key === 3);
      expect(individualView).toBeDefined();
      expect(individualView.value).toBe('Individual View');
    });

    test('all elements have key and value properties', () => {
      UserRoleHeirarchy.forEach((hierarchy) => {
        expect(hierarchy).toHaveProperty('key');
        expect(hierarchy).toHaveProperty('value');
        expect(typeof hierarchy.key).toBe('number');
        expect(typeof hierarchy.value).toBe('string');
      });
    });

    test('keys are sequential starting from 1', () => {
      expect(UserRoleHeirarchy[0].key).toBe(1);
      expect(UserRoleHeirarchy[1].key).toBe(2);
      expect(UserRoleHeirarchy[2].key).toBe(3);
    });
  });

  describe('Integration tests', () => {
    test('user status values match UserStatus object', () => {
      expect(UserStatusValues.find((s) => s.key === UserStatus.Active)).toBeDefined();
      expect(UserStatusValues.find((s) => s.key === UserStatus.Deleted)).toBeDefined();
      expect(UserStatusValues.find((s) => s.key === UserStatus.Deactive)).toBeDefined();
    });

    test('all arrays are non-empty', () => {
      expect(UserStatusValues.length).toBeGreaterThan(0);
      expect(UserRoles.length).toBeGreaterThan(0);
      expect(UserRoleHeirarchy.length).toBeGreaterThan(0);
    });

    test('no overlapping keys between status and roles', () => {
      const statusKeys = UserStatusValues.map((s) => s.key);
      const roleKeys = UserRoles.map((r) => r.key);
      const intersection = statusKeys.filter((k) => roleKeys.includes(k));
      expect(intersection).toHaveLength(0);
    });
  });
});
