# import PaginatorParts from './paginator.fragment.graphql'
fragment OrderParts on Order {
  id
  tracking_number
  customer_contact
  customer_name
  customer {
    name
  }
  shop {
    id
  }
  order_status
  payment_status
  payment_intent {
    id
    order_id
    payment_gateway
    payment_intent_info {
      client_secret
      payment_id
      is_redirect
      redirect_url
    }
  }
  products {
    # id
    name
    price
    sale_price
    created_at
    image {
      id
      original
      thumbnail
    }
    variation_options {
      id
      title
    }
    pivot {
      variation_option_id
      order_quantity
      unit_price
      subtotal
    }
    quantity
    unit
  }
  amount
  sales_tax
  total
  paid_total
  payment_id
  parent_id
  payment_gateway
  altered_payment_gateway
  coupon {
    code
    amount
    type
  }
  discount
  delivery_fee
  delivery_time
  coupon {
    id
    code
  }
  billing_address {
    country
    city
    state
    zip
    street_address
  }
  shipping_address {
    country
    city
    state
    zip
    street_address
  }
  refund {
    id
    title
    amount
    status
  }
  wallet_point {
    id
    amount
  }
  created_at
  updated_at
  language
}
query orders(
  $tracking_number: String
  $orderBy: String
  $sortedBy: String
  $customer_id: ID
  $shop_id: ID
  $first: Int = 10
  $page: Int
) {
  orders(
    tracking_number: $tracking_number
    orderBy: $orderBy
    sortedBy: $sortedBy
    customer_id: $customer_id
    shop_id: $shop_id
    first: $first
    page: $page
  ) {
    data {
      id
      customer_id
      customer {
        name
        email
      }
      children {
        id
        tracking_number
        delivery_fee
        total
        order_status
        payment_status
        shop {
          id
        }
        shipping_address {
          street_address
          country
          city
          zip
          state
        }
        # created_at
      }
      products {
        id
        name
        pivot {
          order_quantity
          unit_price
          subtotal
        }
      }
      tracking_number
      customer {
        id
        name
      }
      customer_contact
      delivery_fee
      sales_tax
      discount
      amount
      total
      paid_total
      order_status
      payment_status
      payment_gateway
      shipping_address {
        street_address
        country
        city
        zip
        state
      }
      created_at
      language
    }
    paginatorInfo {
      ...PaginatorParts
    }
  }
}

query Order($tracking_number: String, $id: ID) {
  order(tracking_number: $tracking_number, id: $id) {
    id
    tracking_number
    customer_contact
    customer_name
    customer {
      name
    }
    shop {
      id
      slug
    }
    children {
      id
      tracking_number
      delivery_fee
      total
      amount
      order_status
      payment_status
      shipping_address {
        street_address
        country
        city
        zip
        state
      }
      products {
        id
        name
        image {
          id
          original
          thumbnail
        }
        slug
        pivot {
          variation_option_id
          order_quantity
          unit_price
          subtotal
        }
        variation_options {
          id
          title
        }
      }
      # created_at
    }
    order_status
    payment_status
    parent_id
    wallet_point {
      id
      amount
    }
    payment_intent {
      id
      order_id
      payment_gateway
      payment_intent_info {
        client_secret
        payment_id
        is_redirect
        redirect_url
      }
    }
    products {
      id
      name
      image {
        id
        original
        thumbnail
      }
      slug
      pivot {
        variation_option_id
        order_quantity
        unit_price
        subtotal
      }
      variation_options {
        id
        title
      }
    }
    amount
    sales_tax
    total
    paid_total
    payment_id
    payment_gateway
    altered_payment_gateway
    coupon {
      code
      amount
      type
    }
    discount
    delivery_fee
    delivery_time
    coupon {
      id
      code
    }
    billing_address {
      country
      city
      state
      zip
      street_address
    }
    shipping_address {
      street_address
      country
      city
      state
      zip
    }
    created_at
    language
  }
}

mutation UpdateOrder($input: UpdateOrderInput!) {
  updateOrder(input: $input) {
    id
    tracking_number
    customer {
      name
    }
    order_status
    payment_status
    payment_intent {
      id
      order_id
      payment_gateway
      payment_intent_info {
        client_secret
        payment_id
        is_redirect
        redirect_url
      }
    }
    products {
      id
      image {
        id
        original
        thumbnail
      }
      slug
      pivot {
        order_quantity
        unit_price
        subtotal
      }
    }
    amount
    sales_tax
    total
    paid_total
    payment_id
    payment_gateway
    altered_payment_gateway
    coupon {
      code
      amount
      type
    }
    discount
    delivery_fee
    delivery_time
    coupon {
      id
      code
    }
    billing_address {
      country
      city
      state
      zip
    }
    shipping_address {
      country
      city
      state
      zip
    }
    created_at
  }
}
mutation DeleteOrder($id: ID!) {
  deleteOrder(id: $id) {
    id
    tracking_number
    customer {
      name
    }
    order_status
    payment_status
    payment_intent {
      id
      order_id
      payment_gateway
      payment_intent_info {
        client_secret
        payment_id
        is_redirect
        redirect_url
      }
    }
    products {
      id
      image {
        id
        original
        thumbnail
      }
      slug
      pivot {
        order_quantity
        unit_price
        subtotal
      }
    }
    amount
    sales_tax
    total
    paid_total
    payment_id
    payment_gateway
    altered_payment_gateway
    coupon {
      code
      amount
      type
    }
    discount
    delivery_fee
    delivery_time
    coupon {
      id
      code
    }
    billing_address {
      country
      city
      state
      zip
    }
    shipping_address {
      country
      city
      state
      zip
    }
    created_at
  }
}

mutation CreateOrder($input: CreateOrderInput!) {
  createOrder(input: $input) {
    ...OrderParts
  }
}

mutation GenerateOrderExportUrl($input: generateOrderExportUrlInput!) {
  generateOrderExportUrl(input: $input)
}

mutation GenerateInvoiceDownloadUrl($input: GenerateInvoiceDownloadUrlInput!) {
  generateInvoiceDownloadUrl(input: $input)
}
