import { ItemDTO } from '@generated/swagger/cat-search-api';
import {
  ShoppingCartItemDTO,
  BranchDTO,
} from '@generated/swagger/checkout-api';
import { Customer } from '@isa/crm/data-access';
import { ActionType, PurchaseOption } from './store';

/**
 * Data interface for opening the Purchase Options Modal.
 *
 * @example
 * ```typescript
 * // Basic usage
 * const modalRef = await purchaseOptionsModalService.open({
 *   tabId: 123,
 *   shoppingCartId: 456,
 *   type: 'add',
 *   items: [item1, item2],
 * });
 *
 * // With disabled options
 * const modalRef = await purchaseOptionsModalService.open({
 *   tabId: 123,
 *   shoppingCartId: 456,
 *   type: 'add',
 *   items: [rewardItem],
 *   disabledPurchaseOptions: ['b2b-delivery'],
 *   hideDisabledPurchaseOptions: true, // Hide completely (default)
 * });
 * ```
 */
export interface PurchaseOptionsModalData {
  /** Tab ID for maintaining context across the application */
  tabId: number;

  /** Shopping cart ID where items will be added or updated */
  shoppingCartId: number;

  /**
   * Action type determining modal behavior:
   * - 'add': Adding new items to cart
   * - 'update': Updating existing cart items
   */
  type: ActionType;

  /**
   * Enable redemption points mode for reward items.
   * When true, prices are set to 0 and loyalty points are applied.
   */
  useRedemptionPoints?: boolean;

  /** Items to display in the modal for purchase option selection */
  items: Array<ItemDTO | ShoppingCartItemDTO>;

  /** Pre-configured branch for pickup option */
  pickupBranch?: BranchDTO;

  /** Pre-configured branch for in-store option */
  inStoreBranch?: BranchDTO;

  /**
   * Pre-select a specific purchase option on modal open.
   * Set showOptionOnly to true to display only that option.
   */
  preSelectOption?: { option: PurchaseOption; showOptionOnly?: boolean };

  /**
   * Purchase options to disable. Disabled options:
   * - Will not have availability API calls made
   * - Will either be hidden or shown as disabled based on hideDisabledPurchaseOptions
   *
   * @example ['b2b-delivery', 'download']
   */
  disabledPurchaseOptions?: PurchaseOption[];

  /**
   * Controls visibility of disabled purchase options.
   * - true (default): Disabled options are completely hidden from the UI
   * - false: Disabled options are shown with a disabled visual state (grayed out, not clickable)
   *
   * @default true
   */
  hideDisabledPurchaseOptions?: boolean;
}

/**
 * Internal context interface used within the modal component.
 * Extends PurchaseOptionsModalData with additional runtime data like selected customer.
 *
 * @internal
 */
export interface PurchaseOptionsModalContext {
  /** Shopping cart ID where items will be added or updated */
  shoppingCartId: number;

  /**
   * Action type determining modal behavior:
   * - 'add': Adding new items to cart
   * - 'update': Updating existing cart items
   */
  type: ActionType;

  /** Enable redemption points mode for reward items */
  useRedemptionPoints: boolean;

  /** Items to display in the modal for purchase option selection */
  items: Array<ItemDTO | ShoppingCartItemDTO>;

  /** Customer selected in the current tab (resolved at runtime) */
  selectedCustomer?: Customer;

  /** Default branch resolved from user settings or tab context */
  selectedBranch?: BranchDTO;

  /** Pre-configured branch for pickup option */
  pickupBranch?: BranchDTO;

  /** Pre-configured branch for in-store option */
  inStoreBranch?: BranchDTO;

  /** Pre-select a specific purchase option on modal open */
  preSelectOption?: { option: PurchaseOption; showOptionOnly?: boolean };

  /** Purchase options to disable (no API calls, conditional UI rendering) */
  disabledPurchaseOptions?: PurchaseOption[];

  /** Controls visibility of disabled purchase options (default: true = hidden) */
  hideDisabledPurchaseOptions?: boolean;
}
