import { describe, it, expect } from 'vitest';
import { shouldShowGrouping } from './should-show-grouping.helper';
import {
  RewardSelectionItem,
  ShoppingCartItem,
} from '@isa/checkout/data-access';

describe('shouldShowGrouping', () => {
  it('should return false for single item', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = shouldShowGrouping(items);

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

  it('should return true when items have different order types', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
      {
        item: {
          features: { orderType: 'Abholung' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = shouldShowGrouping(items);

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

  it('should return false when items have same order type and branch', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = shouldShowGrouping(items);

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

  it('should return true for Abholung with different branches', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: { orderType: 'Abholung' },
          destination: {
            data: { targetBranch: { id: 1 } },
          },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
      {
        item: {
          features: { orderType: 'Abholung' },
          destination: {
            data: { targetBranch: { id: 2 } },
          },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = shouldShowGrouping(items);

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