export namespace SGConnectAPI {

  interface UrlResponse {
    url: string,
    expires: string | undefined
  }

  interface SGAadProduct {
    productId: string
    quantity: number
    options: Array<Object>
    metadata: Object
  }

  interface SGCatalogProduct {
    id: string
    name: string
    active: boolean
    description: string
    identifiers: {
      sku: string
    }
    customData: string // {"store_view_id":1,"product_id":"44","item_type":"simple"}
    productUrl: string // http://localhost/didi-sport-watch.html
    manufacturer: string
    type: string // simple
    stock: {
      ignoreQuantity: boolean // false
      quantity: number
      info: string
      orderable: boolean // true
      minOrderQuantity: number // 1
      maxOrderQuantity: number // 10000
    }
    rating: {
      count: number // 2
      average: number // 70
      reviewCount: number // 2
    }
    price: {
      currency: string // EUR
      info: string
      unitPrice: number
      unitPriceStriked: number
      unitPriceNet: number
      unitPriceWithTax: number
      taxAmount: number
      taxPercent: number
      msrp: number
      discount: number
      tiers: []
    }
    flags: {
      hasChildren: boolean
      hasVariants: boolean
      hasOptions: boolean
    }
    featuredImageUrl: string // Image with color & other properties attached to it
    featuredImageBaseUrl: string // Image with the least properties
  }

  interface SGUpdateProduct {
    cartItemId: string // PWA6.x
    CartItemId: string // PWA5.x
    quantity: number
  }

  interface SGUpdateProductInput {
    cartItems: Array<SGUpdateProduct>
  }

  interface SGDeleteItemInput {
    cartItemIds: Array<string>
  }

  interface CartText {
    legalText: string
    legalInfo: string
  }

  interface Item {
    id: string
    quantity: number
    type: string
    product?: ItemProduct
    coupon?: ItemCoupon
    messages: SGCartMessage[]
  }

  interface ItemProduct {
    id: string
    name: string
    featuredImageUrl: string
    price: ItemProductPrice
    properties?: LabelValue[]
    appliedDiscounts?: [
      {
        code: string, // 20OFF
        label: string // 20% off the cart
        description: string
      }
    ]
    additionalInfo?: LabelValue[] // Define a specific type for additional info
  }

  interface ItemProductPrice {
    unit: number // price per unit without discounts
    default: number // Full non-discounted amount multiplied by quantity, with or without tax
    special: number | null // Full discounted amount multiplied by quantity, with or without tax
  }

  interface SGCartError {
    code: string // e.g. ENOTFOUND
    message: string
    messageParams?: Object
    translated?: boolean // if message is a translated string, defaults to true
  }

  interface ItemCoupon {
    code?: string
    description?: string
    label?: string
    savedPrice: {
      value: number
      type: string
    }
  }

  interface LabelValue {
    label: string // Color
    value: string // Red
  }

  interface Total {
    type: string
    label: string
    amount: number
    subTotals?: SubTotal[]
  }

  interface SubTotal {
    type: string
    label: string
    amount: number
  }

  interface Flags {
    taxIncluded: boolean
    orderable: boolean
    coupons: boolean
  }

  // see https://developer.shopgate.com/references/connect/shopgate-pipelines/cart/shopgate.cart.getcart.v1
  interface SGCartMessage {
    code: string
    type: 'warning' | 'error' | 'info'
    message: string
    messageParams: object // key -> value pairs, see https://github.com/yahoo/intl-messageformat#message-syntax
    translated: boolean
  }

  interface SGCustomerOutput {
    id: string
    mail: string
    firstName?: string
    lastName?: string
    gender?: 'male' | 'female'
    phone?: string
    birthday?: string // YYYY-MM-DD
    userGroups: SGCustomerGroup[]
    customAttributes?: { [key: string]: any }
  }

  interface SGCustomerGroup {
    id: string,
    name: string
  }
}
