import { describe, it, expect } from 'vitest';
import { calculatePriceValue } from './calculate-price-value.helper';
import { RewardSelectionItem } from '@isa/checkout/data-access';

describe('calculatePriceValue', () => {
  it('should return item unit price when available', () => {
    const item: RewardSelectionItem = {
      item: {
        unitPrice: { value: { value: 99.99 } },
      },
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: { value: { value: 89.99 } },
      availabilityPrice: undefined,
      catalogRewardPoints: undefined,
    } as RewardSelectionItem;

    const result = calculatePriceValue(item);

    expect(result).toBe(99.99);
  });

  it('should return availability price when unit price not available', () => {
    const item: RewardSelectionItem = {
      item: {
        availability: { price: { value: { value: 79.99 } } },
      },
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: { value: { value: 89.99 } },
      availabilityPrice: undefined,
      catalogRewardPoints: undefined,
    } as RewardSelectionItem;

    const result = calculatePriceValue(item);

    expect(result).toBe(79.99);
  });

  it('should return catalog price as fallback', () => {
    const item: RewardSelectionItem = {
      item: {},
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: { value: { value: 89.99 } },
      availabilityPrice: undefined,
      catalogRewardPoints: undefined,
    } as RewardSelectionItem;

    const result = calculatePriceValue(item);

    expect(result).toBe(89.99);
  });

  it('should return 0 when no price available', () => {
    const item: RewardSelectionItem = {
      item: {},
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: undefined,
      availabilityPrice: undefined,
      catalogRewardPoints: undefined,
    } as RewardSelectionItem;

    const result = calculatePriceValue(item);

    expect(result).toBe(0);
  });
});
