####
# Base
####

"Additional data from Flat-rate"
type flatRateData {
  gqlType: String
  flatRateData: Int
}

extend union AdditionalData = flatRateData


extend type Query {
  "Get a flat rate fulfillment method"
  flatRateFulfillmentMethod(
    "Fulfillment method id"
    methodId: ID!

    "Shop ID"
    shopId: ID!
  ): FlatRateFulfillmentMethod!

  "Get a flat rate fulfillment methods"
  flatRateFulfillmentMethods(
    "Shop ID"
    shopId: ID!

    "Return only results that come after this cursor. Use this with `first` to specify the number of results to return."
    after: ConnectionCursor,

    "Return only results that come before this cursor. Use this with `last` to specify the number of results to return."
    before: ConnectionCursor,

    "Return at most this many results. This parameter may be used with either `after` or `offset` parameters."
    first: ConnectionLimitInt,

    "Return at most this many results. This parameter may be used with the `before` parameter."
    last: ConnectionLimitInt,

    "Return only results that come after the Nth result. This parameter may be used with the `first` parameter."
    offset: Int,
  ): FlatRateFulfillmentMethodConnection!
}

extend type Mutation {
  "Create a flat rate fulfillment method"
  createFlatRateFulfillmentMethod(
    "Mutation input"
    input: CreateFlatRateFulfillmentMethodInput!
  ): CreateFlatRateFulfillmentMethodPayload!

  "Update a flat rate fulfillment method"
  updateFlatRateFulfillmentMethod(
    "Mutation input"
    input: UpdateFlatRateFulfillmentMethodInput!
  ): UpdateFlatRateFulfillmentMethodPayload!

  "Delete a flat rate fulfillment method"
  deleteFlatRateFulfillmentMethod(
    "Mutation input"
    input: DeleteFlatRateFulfillmentMethodInput!
  ): DeleteFlatRateFulfillmentMethodPayload!
}

"Defines a fulfillment method that has a fixed price. This type is provided by the `flat-rate` fulfillment plugin."
type FlatRateFulfillmentMethod implements Node {
  "The flat rate fulfillment method ID"
  _id: ID!

  "The cost of this fulfillment method to the shop, if you track this"
  cost: Float

  """
  The fulfillment types for which this method may be used. For example, `shipping` or `digital`.
  """
  fulfillmentTypes: [FulfillmentType]!

  "The group to which this method belongs"
  group: String!

  "A fixed price to charge for handling costs when this fulfillment method is selected for an order"
  handling: Float!

  "Include this as a fulfillment option shown to shoppers during checkout?"
  isEnabled: Boolean @deprecated(reason: "Use `enabled`")

  "Replacement field for the deprecated `isEnabled`, matches with the database definition"
  enabled: Boolean

  "The name of this method, for display in the user interface"
  label: String!

  "The name of this method, a unique identifier"
  name: String!

  "The common-name for this method, to group all variants of the same method"
  fulfillmentMethod: String

  "A fixed price to charge for fulfillment costs when this fulfillment method is selected for an order"
  rate: Float!

  "The shop to which this fulfillment method belongs"
  shop: Shop!
}

####
# Inputs
####

"Defines a fulfillment method that has a fixed price. This type is provided by the `flat-rate` fulfillment plugin."
input FlatRateFulfillmentMethodInput {
  "The cost of this fulfillment method to the shop, if you track this"
  cost: Float

  """
  The fulfillment types for which this method may be used. For example, `shipping` or `digital`.
  """
  fulfillmentTypes: [FulfillmentType]!

  "The group to which this method belongs"
  group: String!

  "A fixed price to charge for handling costs when this fulfillment method is selected for an order"
  handling: Float!

  "Include this as a fulfillment option shown to shoppers during checkout?"
  isEnabled: Boolean @deprecated(reason: "Use `enabled`")

  "Replacement field for the deprecated `isEnabled`, matches with the database definition"
  enabled: Boolean

  "The name of this method, for display in the user interface"
  label: String!

  "The name of this method, a unique identifier"
  name: String!

  "The common-name for this method, to group all variants of the same method"
  fulfillmentMethod: String

  "A fixed price to charge for fulfillment costs when this fulfillment method is selected for an order"
  rate: Float!
}

"Input for the `createFlatRateFulfillmentMethod` mutation"
input CreateFlatRateFulfillmentMethodInput {
  "An optional string identifying the mutation call, which will be returned in the response payload"
  clientMutationId: String

  "This defines the flat rate fulfillment method that you want to create"
  method: FlatRateFulfillmentMethodInput!

  "The shop to create this flat rate fulfillment method for"
  shopId: ID!
}

"Input for the `updateFlatRateFulfillmentMethod` mutation"
input UpdateFlatRateFulfillmentMethodInput {
  "An optional string identifying the mutation call, which will be returned in the response payload"
  clientMutationId: String

  "The updated method. Pass the whole updated method object without the ID."
  method: FlatRateFulfillmentMethodInput!

  "The ID of the flat rate fulfillment method you want to update"
  methodId: ID!

  "The shop that owns the method"
  shopId: ID!
}

"Input for the `deleteFlatRateFulfillmentMethod` mutation"
input DeleteFlatRateFulfillmentMethodInput {
  "An optional string identifying the mutation call, which will be returned in the response payload"
  clientMutationId: String

  "The ID of the flat rate fulfillment method you want to delete"
  methodId: ID!

  "The shop that owns the method"
  shopId: ID!
}

####
# Payloads
####

"Response from the `createFlatRateFulfillmentMethod` mutation"
type CreateFlatRateFulfillmentMethodPayload {
  "The same string you sent with the mutation params, for matching mutation calls with their responses"
  clientMutationId: String

  "The created fulfillment method"
  method: FlatRateFulfillmentMethod!
}

"Response from the `updateFlatRateFulfillmentMethod` mutation"
type UpdateFlatRateFulfillmentMethodPayload {
  "The same string you sent with the mutation params, for matching mutation calls with their responses"
  clientMutationId: String

  "The updated fulfillment method"
  method: FlatRateFulfillmentMethod!
}

"Response from the `deleteFlatRateFulfillmentMethod` mutation"
type DeleteFlatRateFulfillmentMethodPayload {
  "The same string you sent with the mutation params, for matching mutation calls with their responses"
  clientMutationId: String

  "The removed fulfillment method"
  method: FlatRateFulfillmentMethod!
}

####
# Connections
####

"A connection edge in which each node is a `FlatRateFulfillmentMethod` object"
type FlatRateFulfillmentMethodEdge {
  "The cursor that represents this node in the paginated results"
  cursor: ConnectionCursor!

  "The fulfillment method"
  node: FlatRateFulfillmentMethod
}

"""
Wraps a list of FlatRateFulfillmentMethods`s, providing pagination cursors and information.

For information about what Relay-compatible connections are and how to use them, see the following articles:
- [Relay Connection Documentation](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections)
- [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm)
- [Using Relay-style Connections With Apollo Client](https://www.apollographql.com/docs/react/recipes/pagination.html)
"""
type FlatRateFulfillmentMethodConnection {
  "The list of nodes that match the query, wrapped in an edge to provide a cursor string for each"
  edges: [FlatRateFulfillmentMethodEdge]

  """
  You can request the `nodes` directly to avoid the extra wrapping that `NodeEdge` has,
  if you know you will not need to paginate the results.
  """
  nodes: [FlatRateFulfillmentMethod]

  "Information to help a client request the next or previous page"
  pageInfo: PageInfo!

  "The total number of nodes that match your query"
  totalCount: Int!
}

extend type ShopSettings {
  """
  If `false` no defined shipping rates will be used when fulfillment
  quotes are requested for a cart or order. A quick way to disable the entire
  `reaction-shipping-rates` plugin temporarily.
  """
  isShippingRatesFulfillmentEnabled: Boolean
}

extend input ShopSettingsUpdates {
  """
  Set to `false` to prevent any defined shipping rates from being used when fulfillment
  quotes are requested for a cart or order. A quick way to disable the entire
  `reaction-shipping-rates` plugin temporarily.
  """
  isShippingRatesFulfillmentEnabled: Boolean
}
