import { describe, test, expect } from 'vitest';
import { BrowserAuthenticationState } from 'apps/companion/main/automation/domain/value-objects/BrowserAuthenticationState';
import { AuthenticationState } from 'apps/companion/main/automation/domain/value-objects/AuthenticationState';

describe('BrowserAuthenticationState', () => {
  describe('isFullyAuthenticated()', () => {
    test('should return true when both cookies and page authenticated', () => {
      const state = new BrowserAuthenticationState(true, true);
      
      expect(state.isFullyAuthenticated()).toBe(true);
    });

    test('should return false when cookies valid but page unauthenticated', () => {
      const state = new BrowserAuthenticationState(true, false);
      
      expect(state.isFullyAuthenticated()).toBe(false);
    });

    test('should return false when cookies invalid but page authenticated', () => {
      const state = new BrowserAuthenticationState(false, true);
      
      expect(state.isFullyAuthenticated()).toBe(false);
    });

    test('should return false when both cookies and page unauthenticated', () => {
      const state = new BrowserAuthenticationState(false, false);
      
      expect(state.isFullyAuthenticated()).toBe(false);
    });
  });

  describe('getAuthenticationState()', () => {
    test('should return AUTHENTICATED when both cookies and page authenticated', () => {
      const state = new BrowserAuthenticationState(true, true);
      
      expect(state.getAuthenticationState()).toBe(AuthenticationState.AUTHENTICATED);
    });

    test('should return EXPIRED when cookies valid but page unauthenticated', () => {
      const state = new BrowserAuthenticationState(true, false);
      
      expect(state.getAuthenticationState()).toBe(AuthenticationState.EXPIRED);
    });

    test('should return UNKNOWN when cookies invalid', () => {
      const state = new BrowserAuthenticationState(false, false);
      
      expect(state.getAuthenticationState()).toBe(AuthenticationState.UNKNOWN);
    });

    test('should return UNKNOWN when cookies invalid regardless of page state', () => {
      const state = new BrowserAuthenticationState(false, true);
      
      expect(state.getAuthenticationState()).toBe(AuthenticationState.UNKNOWN);
    });
  });

  describe('requiresReauthentication()', () => {
    test('should return false when fully authenticated', () => {
      const state = new BrowserAuthenticationState(true, true);
      
      expect(state.requiresReauthentication()).toBe(false);
    });

    test('should return true when cookies valid but page unauthenticated', () => {
      const state = new BrowserAuthenticationState(true, false);
      
      expect(state.requiresReauthentication()).toBe(true);
    });

    test('should return true when cookies invalid', () => {
      const state = new BrowserAuthenticationState(false, false);
      
      expect(state.requiresReauthentication()).toBe(true);
    });

    test('should return true when cookies invalid but page authenticated', () => {
      const state = new BrowserAuthenticationState(false, true);
      
      expect(state.requiresReauthentication()).toBe(true);
    });
  });

  describe('getCookieValidity()', () => {
    test('should return true when cookies are valid', () => {
      const state = new BrowserAuthenticationState(true, true);
      
      expect(state.getCookieValidity()).toBe(true);
    });

    test('should return false when cookies are invalid', () => {
      const state = new BrowserAuthenticationState(false, false);
      
      expect(state.getCookieValidity()).toBe(false);
    });
  });

  describe('getPageAuthenticationStatus()', () => {
    test('should return true when page is authenticated', () => {
      const state = new BrowserAuthenticationState(true, true);
      
      expect(state.getPageAuthenticationStatus()).toBe(true);
    });

    test('should return false when page is unauthenticated', () => {
      const state = new BrowserAuthenticationState(true, false);
      
      expect(state.getPageAuthenticationStatus()).toBe(false);
    });
  });
});