import { Money } from './money.vo';

describe('Money', () => {
  describe('USDT factory', () => {
    it('should create Money with USDT currency', () => {
      const money = Money.USDT(100);
      expect(money.amount).toBe(100);
      expect(money.currency).toBe('USDT');
    });
  });

  describe('zero factory', () => {
    it('should create zero Money', () => {
      const money = Money.zero();
      expect(money.amount).toBe(0);
      expect(money.isZero()).toBe(true);
    });
  });

  describe('validation', () => {
    it('should throw error for negative amount', () => {
      expect(() => Money.USDT(-100)).toThrow('金额不能为负数');
    });
  });

  describe('add', () => {
    it('should add two Money values', () => {
      const a = Money.USDT(100);
      const b = Money.USDT(50);
      const result = a.add(b);
      expect(result.amount).toBe(150);
    });
  });

  describe('subtract', () => {
    it('should subtract Money values', () => {
      const a = Money.USDT(100);
      const b = Money.USDT(30);
      const result = a.subtract(b);
      expect(result.amount).toBe(70);
    });

    it('should return zero when subtracting larger value', () => {
      const a = Money.USDT(50);
      const b = Money.USDT(100);
      const result = a.subtract(b);
      expect(result.amount).toBe(0);
    });
  });

  describe('multiply', () => {
    it('should multiply Money by factor', () => {
      const money = Money.USDT(100);
      const result = money.multiply(3);
      expect(result.amount).toBe(300);
    });
  });

  describe('equals', () => {
    it('should return true for equal values', () => {
      const a = Money.USDT(100);
      const b = Money.USDT(100);
      expect(a.equals(b)).toBe(true);
    });

    it('should return false for different values', () => {
      const a = Money.USDT(100);
      const b = Money.USDT(50);
      expect(a.equals(b)).toBe(false);
    });
  });

  describe('isGreaterThan', () => {
    it('should return true when greater', () => {
      const a = Money.USDT(100);
      const b = Money.USDT(50);
      expect(a.isGreaterThan(b)).toBe(true);
    });

    it('should return false when less or equal', () => {
      const a = Money.USDT(50);
      const b = Money.USDT(100);
      expect(a.isGreaterThan(b)).toBe(false);
    });
  });
});
