"""
Shipment information
Track your shipment. Get the latest information on your shipment status. 
"""

name = "delivery-tracking/shipment-info"
version = "1.1.1"

"""
Retrieve Shipment Status
Get the current shipment status.
"""
usecase ShipmentInfo safe {
  input {
    """
    Shipment tracking number
    The identifier of shipment.
    """
    trackingNumber! string!

    """
    Carrier
    The shipment carrier identification to narrow down the results.
    """
    carrier string!
  }

  result [{
    """
    Carrier
    The name of the carrier responsible for delivery.
    """
    carrier! string

    """
    Status
    The latest shipment event.
    """
    status! ShipmentEvent

    """
    Origin
    A postal address with the origin of the shipment.
    """
    origin! Location

    """
    Shipment tracking number
    The identifier of shipment.
    """
    trackingNumber! string
    
    """
    Destination
    A postal shipping address.
    """
    destination! Location

    """
    Events
    A list of delivery tracking events.
    """
    events! [ShipmentEvent!]!

    """
    Estimated delivery date
    Estimated date and time of delivery.
    """
    estimatedDeliveryDate! string
  }]

  error {
    """
    Title
    A short, human-readable summary of the problem type.
    """
    title!

    """
    Detail
    A human-readable explanation specific to this occurrence of the problem.
    """
    detail
  }

  example Successful {
    input {
      trackingNumber = '00340434292135100148'
    }

    result [{
      carrier = 'shippo',
      destination = {
        address = {
          addressLocality = 'Chicago',
          countryCode = 'US',
          postalCode = '60611',
        },
      },
      estimatedDeliveryDate = '2021-11-08T07:03:30.944Z',
      events = [
        {
          statusCode = 'unknown',
          statusText = 'The carrier has received the electronic shipment information.',
          timestamp = '2021-11-01T19:54:08.906Z',
        },
        {
          location = {
            address = {
              addressLocality = 'San Francisco',
              countryCode = 'US',
              postalCode = '94103',
            },
          },
          statusCode = 'transit',
          statusText = 'Your shipment has departed from the origin.',
          timestamp = '2021-11-02T23:54:08.906Z',
        },
        {
          location = {
            address =  {
              addressLocality = 'Memphis',
              countryCode = 'US',
              postalCode = '37501',
            },
          },
          statusCode = 'failure',
          statusText = 'The Postal Service has identified a problem with the processing of this item and you should contact support to get further information.',
          timestamp = '2021-11-04T11:54:08.906Z',
        },
        {
          location = {
            address =  {
              addressLocality = 'Chicago',
              countryCode = 'US',
              postalCode = '60611',
            },
          },
          statusCode = 'delivered',
          statusText = 'Your shipment has been delivered.',
          timestamp = '2021-11-03T23:54:08.906Z',
        },
      ],
      origin = {
        address = {
          addressLocality = 'San Francisco',
          countryCode = 'US',
          postalCode = '94103',
        },
      },
      status = {
        location = {
          address = {
            addressLocality = 'Chicago',
            countryCode = 'US',
            postalCode = '60611',
          },
        },
        statusCode = 'delivered',
        statusText = 'Your shipment has been delivered.',
        timestamp = '2021-11-03T23:54:08.906Z',
      },
      trackingNumber = '00340434292135100148',
      },
    ]
  }

  example Failed {
    input {
      trackingNumber = '12345'
    }

    error {
      title = 'No shipment with given tracking number found'
    }
  }
}

"""
Shipment status
The status of the shipment. Harmonized across different carriers.
"""
model ShipmentStatus enum {
  """
  Pre-Transit
  Carrier has received information about the package but it has not yet been scanned and picked up.
  """
  pre_transit

  """
  Transit
  A package is traveling to its destination.
  """
  transit

  """
  Delivered
  The package has been delivered.
  """
  delivered

  """
  Failure
  The package encountered an error during transit.
  """
  failure

  """
  Unknown
  The shipment status is unknown.
  """
  unknown
}

"""
Shipment event
The shipment event information.
"""
model ShipmentEvent {
  """
  Timestamp
  The date and time in ISO 8601 format of the event.
  """
  timestamp! string

  """
  Shipment status
  The shipment status of the event.
  """
  statusCode! ShipmentStatus

  """
  Status
  A description of the current shipment status.
  """
  statusText! string

  """
  Location
  The location of the shipment.
  """
  location Location
}

"""
Location
A shipment location.
"""
model Location {
  address! {
    """
    Country code
    A short text string code (ISO 3166-1 alpha-2 country code) specifying the country.
    """
    countryCode string

    """
    Postal code
    Text specifying the postal code for an address.
    """
    postalCode string

    """
    Address locality
    Text specifying the name of the locality, for example a city.
    """
    addressLocality string

    """
    Street address
    The street address expressed as free form text. The street address is printed on paper as the first lines below the name.
    """
    streetAddress string
  }
}