import { describe, expect, it } from 'vitest';
import { buildSimpleTradePayload, computeProtectionPrices } from './SimpleView';

describe('SimpleView helpers', () => {
  it('computes buy-side protection prices from reference price', () => {
    expect(
      computeProtectionPrices({
        side: 'buy',
        referencePrice: 100,
        stopLossPercent: 5,
        takeProfitPercent: 8,
      }),
    ).toEqual({ sl: 95, tp: 108 });
  });

  it('computes sell-side protection prices from reference price', () => {
    expect(
      computeProtectionPrices({
        side: 'sell',
        referencePrice: 100,
        stopLossPercent: 5,
        takeProfitPercent: 8,
      }),
    ).toEqual({ sl: 105, tp: 92 });
  });

  it('builds a market buy trade payload from market price', () => {
    const payload = buildSimpleTradePayload({
      symbol: 'aapl',
      side: 'buy',
      orderType: 'market',
      quantity: '5',
      limitPrice: '',
      currentMarketPrice: '210.25',
      stopLossPercent: '4',
      takeProfitPercent: '10',
      isCrypto: false,
    });

    expect(payload).toEqual({
      symbol: 'AAPL',
      side: 'buy',
      qty: 5,
      type: 'market',
      sl: 201.84,
      tp: 231.275,
    });
  });

  it('builds a limit sell trade payload from limit price', () => {
    const payload = buildSimpleTradePayload({
      symbol: 'btc/usd',
      side: 'sell',
      orderType: 'limit',
      quantity: '0.25',
      limitPrice: '64000',
      currentMarketPrice: '65000',
      stopLossPercent: '3',
      takeProfitPercent: '6',
      isCrypto: true,
    });

    expect(payload).toEqual({
      symbol: 'BTC/USD',
      side: 'sell',
      qty: 0.25,
      type: 'limit',
      price: 64000,
      sl: 65920,
      tp: 60160,
    });
  });
});
