import { inject, Injectable } from '@angular/core';
import { LogisticianDTO } from '@generated/swagger/oms-api';
import { DisplayOrder } from '../models';
import { OrderCreationService } from '../services';

/**
 * Facade for order creation operations.
 *
 * @remarks
 * This facade provides a simplified interface for creating orders from checkout
 * and retrieving logistician information. It delegates to OrderCreationService
 * for all operations.
 */
@Injectable({ providedIn: 'root' })
export class OrderCreationFacade {
  #orderCreationService = inject(OrderCreationService);

  /**
   * Creates orders from a checkout.
   *
   * @param checkoutId - The ID of the checkout to create orders from
   * @returns Promise resolving to array of created orders
   * @throws {Error} If checkoutId is invalid or order creation fails
   */
  async createOrdersFromCheckout(checkoutId: number): Promise<DisplayOrder[]> {
    return this.#orderCreationService.createOrdersFromCheckout(checkoutId);
  }

  /**
   * Retrieves logistician information.
   *
   * @param logisticianNumber - The logistician number to retrieve (defaults to '2470')
   * @param abortSignal - Optional signal to abort the operation
   * @returns Promise resolving to logistician data
   * @throws {Error} If logistician is not found or request fails
   */
  async getLogistician(
    logisticianNumber = '2470',
    abortSignal?: AbortSignal,
  ): Promise<LogisticianDTO> {
    return this.#orderCreationService.getLogistician(
      logisticianNumber,
      abortSignal,
    );
  }
}
