import { VersionCode } from '../../../../src/domain/value-objects/version-code.vo';
import { DomainException } from '../../../../src/shared/exceptions/domain.exception';

describe('VersionCode Value Object', () => {
  describe('create', () => {
    it('should create valid version code', () => {
      const versionCode = VersionCode.create(100);
      expect(versionCode.value).toBe(100);
    });

    it('should throw error for non-integer', () => {
      expect(() => VersionCode.create(1.5)).toThrow(DomainException);
      expect(() => VersionCode.create(1.5)).toThrow('VersionCode must be an integer');
    });

    it('should throw error for zero', () => {
      expect(() => VersionCode.create(0)).toThrow(DomainException);
      expect(() => VersionCode.create(0)).toThrow('VersionCode must be positive');
    });

    it('should throw error for negative number', () => {
      expect(() => VersionCode.create(-1)).toThrow(DomainException);
      expect(() => VersionCode.create(-1)).toThrow('VersionCode must be positive');
    });
  });

  describe('comparison methods', () => {
    it('should compare version codes correctly', () => {
      const v1 = VersionCode.create(100);
      const v2 = VersionCode.create(200);

      expect(v2.isNewerThan(v1)).toBe(true);
      expect(v1.isNewerThan(v2)).toBe(false);
    });

    it('should return false for equal versions', () => {
      const v1 = VersionCode.create(100);
      const v2 = VersionCode.create(100);

      expect(v1.isNewerThan(v2)).toBe(false);
      expect(v2.isNewerThan(v1)).toBe(false);
    });
  });

  describe('equals', () => {
    it('should return true for same values', () => {
      const v1 = VersionCode.create(100);
      const v2 = VersionCode.create(100);

      expect(v1.equals(v2)).toBe(true);
    });

    it('should return false for different values', () => {
      const v1 = VersionCode.create(100);
      const v2 = VersionCode.create(200);

      expect(v1.equals(v2)).toBe(false);
    });
  });

  describe('toString', () => {
    it('should return string representation', () => {
      const versionCode = VersionCode.create(100);
      expect(versionCode.toString()).toBe('100');
    });
  });
});
