import { ItemData as AvailabilityItemData } from '@domain/availability';
import { ItemDTO } from '@generated/swagger/cat-search-api';
import {
  AvailabilityDTO,
  BranchDTO,
  ItemPayload,
  ShoppingCartItemDTO,
} from '@generated/swagger/checkout-api';

/**
 * Action type for the purchase options modal.
 * - 'add': Adding new items to the shopping cart
 * - 'update': Updating existing items in the shopping cart
 */
export type ActionType = 'add' | 'update';

/**
 * Available purchase options for item delivery/fulfillment.
 *
 * Each option represents a different way customers can receive their items:
 * - `delivery`: Standard home/address delivery
 * - `dig-delivery`: Digital delivery (special handling)
 * - `b2b-delivery`: Business-to-business delivery
 * - `pickup`: Pickup at a branch location
 * - `in-store`: Reserve and collect in store
 * - `download`: Digital download (e-books, digital content)
 * - `catalog`: Catalog availability (reference only)
 */
export type PurchaseOption =
  | 'delivery'
  | 'dig-delivery'
  | 'b2b-delivery'
  | 'pickup'
  | 'in-store'
  | 'download'
  | 'catalog';

export type ItemDTOWithQuantity = ItemDTO & { quantity?: number };

export type Item = ItemDTOWithQuantity | ShoppingCartItemDTO;

export type Branch = BranchDTO;

export type Availability = {
  itemId: number;
  purchaseOption: PurchaseOption;
  data: AvailabilityDTO & {
    priceMaintained?: boolean;
    orderDeadline?: string;
    firstDayOfSale?: string;
  };
  ean?: string;
};

export type ItemData = AvailabilityItemData & {
  sourceId: number;
  quantity: number;
};

export type ItemPayloadWithSourceId = ItemPayload & { sourceId: number };

export type CanAdd = {
  itemId: number;
  purchaseOption: PurchaseOption;
  canAdd: boolean;
  message?: string;
};

export type FetchingAvailability = {
  id: string;
  itemId: number;
  purchaseOption?: PurchaseOption;
};
