import { describe, it, expect } from 'vitest';
import { detectDirection, PAYMENT_PACKAGES, PAYMENT_PACKAGE_SET } from '../src/domain/core/constants';

describe('detectDirection', () => {
  describe('refund priority', () => {
    it('detects refund', () => {
      expect(detectDirection('退款100元')).toBe('refund');
    });

    it('detects return', () => {
      expect(detectDirection('退回50元')).toBe('refund');
    });
  });

  describe('fee priority', () => {
    it('detects fee', () => {
      expect(detectDirection('手续费2元')).toBe('fee');
    });

    it('detects interest', () => {
      expect(detectDirection('利息收入')).toBe('income');
    });
  });

  describe('income detection', () => {
    it('detects 转入 as income', () => {
      expect(detectDirection('转入1000')).toBe('income');
    });

    it('detects 收入 as income', () => {
      expect(detectDirection('收入5000')).toBe('income');
    });

    it('detects 到账 as income', () => {
      expect(detectDirection('到账100')).toBe('income');
    });

    it('detects 入账 as income', () => {
      expect(detectDirection('入账200')).toBe('income');
    });

    it('detects 向你转账 as income', () => {
      expect(detectDirection('向你转账')).toBe('income');
    });

    it('detects 收到转账 as income', () => {
      expect(detectDirection('收到转账')).toBe('income');
    });
  });

  describe('expense detection', () => {
    it('detects 支出 as expense', () => {
      expect(detectDirection('支出100')).toBe('expense');
    });

    it('detects 付款 as expense', () => {
      expect(detectDirection('付款50')).toBe('expense');
    });

    it('detects 消费 as expense', () => {
      expect(detectDirection('消费200')).toBe('expense');
    });

    it('detects 转出 as expense', () => {
      expect(detectDirection('转出300')).toBe('expense');
    });
  });

  describe('transfer detection', () => {
    it('detects 转账 as transfer', () => {
      expect(detectDirection('转账')).toBe('transfer');
    });
  });

  describe('收款方 guard', () => {
    it('returns defaultDir for 收款方', () => {
      expect(detectDirection('商户:收款方')).toBe('expense');
    });

    it('returns custom defaultDir for 收款方', () => {
      expect(detectDirection('商户:收款方', 'income')).toBe('income');
    });
  });

  describe('收款 detection', () => {
    it('detects 收款 as income', () => {
      expect(detectDirection('收款')).toBe('income');
    });
  });

  describe('default direction', () => {
    it('returns expense as default', () => {
      expect(detectDirection('随机文本')).toBe('expense');
    });

    it('returns custom default', () => {
      expect(detectDirection('随机文本', 'income')).toBe('income');
    });
  });
});

describe('PAYMENT_PACKAGES', () => {
  it('contains Alipay', () => {
    expect(PAYMENT_PACKAGES['com.eg.android.AlipayGphone']).toBe('支付宝');
  });

  it('contains WeChat', () => {
    expect(PAYMENT_PACKAGES['com.tencent.mm']).toBe('微信');
  });
});

describe('PAYMENT_PACKAGE_SET', () => {
  it('contains Alipay package', () => {
    expect(PAYMENT_PACKAGE_SET.has('com.eg.android.AlipayGphone')).toBe(true);
  });

  it('does not contain unknown package', () => {
    expect(PAYMENT_PACKAGE_SET.has('com.unknown.app')).toBe(false);
  });
});
