/**
 * ShipStation API Types
 * Type definitions for ShipStation API requests and responses
 */

/**
 * ShipStation Address Format
 */
export interface ShipStationAddress {
  name: string
  company?: string
  street1: string
  street2?: string
  street3?: string
  city: string
  state: string
  postalCode: string
  country: string
  phone?: string
  residential?: boolean
}

/**
 * ShipStation Line Item
 */
export interface ShipStationLineItem {
  lineItemKey?: string
  sku: string
  name: string
  imageUrl?: string
  weight?: {
    value: number
    units: "pounds" | "ounces" | "grams"
  }
  quantity: number
  unitPrice: number
  taxAmount?: number
  shippingAmount?: number
  warehouseLocation?: string
  options?: Array<{
    name: string
    value: string
  }>
  productId?: number
  fulfillmentSku?: string
  adjustment?: boolean
  upc?: string
}

/**
 * ShipStation Order Request
 */
export interface ShipStationOrder {
  orderNumber: string
  orderKey?: string
  orderDate: string
  paymentDate?: string
  shipByDate?: string
  orderStatus: "awaiting_payment" | "awaiting_shipment" | "shipped" | "on_hold" | "cancelled"
  customerUsername?: string
  customerEmail?: string
  billTo: ShipStationAddress
  shipTo: ShipStationAddress
  items: ShipStationLineItem[]
  amountPaid?: number
  taxAmount?: number
  shippingAmount?: number
  customerNotes?: string
  internalNotes?: string
  gift?: boolean
  giftMessage?: string
  paymentMethod?: string
  requestedShippingService?: string
  carrierCode?: string
  serviceCode?: string
  packageCode?: string
  confirmation?: string
  shipDate?: string
  holdUntilDate?: string
  weight?: {
    value: number
    units: "pounds" | "ounces" | "grams"
  }
  dimensions?: {
    length: number
    width: number
    height: number
    units: "inches" | "centimeters"
  }
  insuranceOptions?: {
    provider: string
    insureShipment: boolean
    insuredValue: number
  }
  internationalOptions?: {
    contents?: string
    customsItems?: any[]
    nonDelivery?: string
  }
  advancedOptions?: {
    warehouseId?: number
    nonMachinable?: boolean
    saturdayDelivery?: boolean
    containsAlcohol?: boolean
    storeId?: number
    customField1?: string
    customField2?: string
    customField3?: string
    source?: string
    mergedOrSplit?: boolean
    mergedIds?: number[]
    parentId?: number
    billToParty?: string
    billToAccount?: string
    billToPostalCode?: string
    billToCountryCode?: string
  }
  tagIds?: number[]
}

/**
 * ShipStation Order Response
 */
export interface ShipStationOrderResponse {
  orderId: number
  orderNumber: string
  orderKey: string
  orderDate: string
  createDate: string
  modifyDate: string
  paymentDate: string | null
  shipByDate: string | null
  orderStatus: string
  customerId: number | null
  customerUsername: string
  customerEmail: string
  billTo: ShipStationAddress
  shipTo: ShipStationAddress
  items: ShipStationLineItem[]
  orderTotal: number
  amountPaid: number
  taxAmount: number
  shippingAmount: number
  customerNotes: string | null
  internalNotes: string | null
  gift: boolean
  giftMessage: string | null
  paymentMethod: string | null
  requestedShippingService: string | null
  carrierCode: string | null
  serviceCode: string | null
  packageCode: string | null
  confirmation: string | null
  shipDate: string | null
  holdUntilDate: string | null
  weight: {
    value: number
    units: string
  } | null
  dimensions: {
    length: number
    width: number
    height: number
    units: string
  } | null
  insuranceOptions: any | null
  internationalOptions: any | null
  advancedOptions: any | null
  tagIds: number[] | null
  userId: string | null
  externallyFulfilled: boolean
  externallyFulfilledBy: string | null
}

/**
 * ShipStation Error Response
 */
export interface ShipStationError {
  message: string
  ExceptionMessage?: string
  ExceptionType?: string
  StackTrace?: string
}

/**
 * ShipStation Webhook Payload
 */
export interface ShipStationWebhookPayload {
  resource_url: string
  resource_type: "SHIP_NOTIFY" | "ITEM_SHIPPED" | "ITEM_ORDER_NOTIFY" | "ORDER_NOTIFY"
  order_id?: number
  order_number?: string
  tracking_number?: string
  carrier?: string
  ship_date?: string
}

/**
 * ShipStation Order Creation Result
 */
export interface ShipStationOrderResult {
  success: boolean
  orderId?: number
  orderNumber?: string
  error?: string
  errorDetails?: any
}




