import { Hashpower } from './hashpower.vo';

jest.mock('@/shared/exceptions/domain.exception', () => ({
  DomainError: class DomainError extends Error {
    constructor(message: string) {
      super(message);
      this.name = 'DomainError';
    }
  },
}));

describe('Hashpower Value Object', () => {
  describe('create', () => {
    it('should create hashpower with valid value', () => {
      const hp = Hashpower.create(100);
      expect(hp.value).toBe(100);
    });

    it('should create zero hashpower', () => {
      const hp = Hashpower.zero();
      expect(hp.value).toBe(0);
      expect(hp.isZero()).toBe(true);
    });

    it('should throw error for negative value', () => {
      expect(() => Hashpower.create(-10)).toThrow('cannot be negative');
    });
  });

  describe('arithmetic operations', () => {
    it('should add hashpower', () => {
      const hp1 = Hashpower.create(100);
      const hp2 = Hashpower.create(50);
      const result = hp1.add(hp2);
      expect(result.value).toBe(150);
    });

    it('should subtract hashpower', () => {
      const hp1 = Hashpower.create(100);
      const hp2 = Hashpower.create(30);
      const result = hp1.subtract(hp2);
      expect(result.value).toBe(70);
    });

    it('should throw error when subtracting more than available', () => {
      const hp1 = Hashpower.create(30);
      const hp2 = Hashpower.create(50);
      expect(() => hp1.subtract(hp2)).toThrow('Insufficient');
    });
  });

  describe('comparison operations', () => {
    it('should check equality', () => {
      const hp1 = Hashpower.create(100);
      const hp2 = Hashpower.create(100);
      expect(hp1.equals(hp2)).toBe(true);
    });

    it('should compare less than', () => {
      const hp1 = Hashpower.create(50);
      const hp2 = Hashpower.create(100);
      expect(hp1.lessThan(hp2)).toBe(true);
    });

    it('should compare greater than', () => {
      const hp1 = Hashpower.create(100);
      const hp2 = Hashpower.create(50);
      expect(hp1.greaterThan(hp2)).toBe(true);
    });

    it('should check isPositive', () => {
      expect(Hashpower.create(100).isPositive()).toBe(true);
      expect(Hashpower.zero().isPositive()).toBe(false);
    });
  });
});
