Put Service Request
*******************

This type of service request is used for inventory inbound into the butler
system.

Put Request Lifecycle
=====================

.. todo:: Have to write this.

Create a Put Request
====================

.. http:post:: /api-gateway/sr-service/platform-srms/service-request

   To create a new put service request, a :ref:`Service Request Object` should
   be sent in a HTTP POST request to the above endpoint. The newly created or
   modified object will be returned in the response if the request is
   successful.

   Put requests should have the :js:data:`type` parameter set to ``PUT``.

   :reqheader Content-Type: the request's content-type has to be passed in this
                            header
   :reqheader Accept: the response content type depends on
                      :mailheader:`Accept` header
   :reqheader Authorization: OAuth token to authenticate
   :statuscode 200: No error
   :statuscode 400: Bad data

   .. container:: toggle

      .. container:: header

         **Example request**:

      .. sourcecode:: http

         POST /api-gateway/sr-service/platform-srms/service-request HTTP/1.1
         Host: example.com
         Content-Type: application/json
         Accept: application/json, text/javascript

      .. literalinclude:: put/create_put_request.json
         :language: JSON

   .. container:: toggle

      .. container:: header

         **Example Response**:
      
      .. sourcecode:: http

         HTTP/1.1 200 OK
         Content-Type: application/json;charset=UTF-8

      .. literalinclude:: put/create_put_response.json
         :language: JSON


Cancel a Put Request
====================

.. http:post:: /api-gateway/sr-service/platform-srms/service-request/cancel

   A Put request can only be modified or cancelled when it is in ``CREATED``
   state. Please consult the :ref:`Put Request Lifecycle` for details.

   :reqheader Content-Type: the request's content-type has to be passed in this
                            header
   :reqheader Accept: the response content type depends on
                      :mailheader:`Accept` header
   :reqheader Authorization: OAuth token to authenticate
   :statuscode 200: No error
   :statuscode 400: Bad data

   .. container:: toggle

      .. container:: header

         **Example request**:

      .. sourcecode:: http

         POST /api-gateway/sr-service/platform-srms/service-request/cancel HTTP/1.1
         Host: example.com
         Content-Type: application/json
         Accept: application/json, text/javascript

      .. literalinclude:: put/cancel_put_request.json
         :language: JSON

   .. container:: toggle

      .. container:: header

         **Example Response**:
      
      .. sourcecode:: http

         HTTP/1.1 200 OK
         Content-Type: application/json;charset=UTF-8

      .. literalinclude:: put/cancel_put_response.json
         :language: JSON


Modify a Put Request
====================

.. http:post:: /api-gateway/sr-service/platform-srms/service-request/modify

   A Put request can only be modified or cancelled when it is in ``CREATED``
   state. Please consult the :ref:`Put Request Lifecycle` for details.

   :reqheader Content-Type: the request's content-type has to be passed in this
                            header
   :reqheader Accept: the response content type depends on
                      :mailheader:`Accept` header
   :reqheader Authorization: OAuth token to authenticate
   :statuscode 200: No error
   :statuscode 400: Bad data

   .. container:: toggle

      .. container:: header

         **Example request**:

      .. sourcecode:: http

         POST /api-gateway/sr-service/platform-srms/service-request/modify HTTP/1.1
         Host: example.com
         Content-Type: application/json
         Accept: application/json, text/javascript

      .. literalinclude:: put/modify_put_request.json
         :language: JSON

   .. container:: toggle

      .. container:: header

         **Example Response**:
      
      .. sourcecode:: http

         HTTP/1.1 200 OK
         Content-Type: application/json;charset=UTF-8

      .. literalinclude:: put/modify_put_response.json
         :language: JSON

Put Request Notifications
=========================

All Put Request notifications follow the generic notification format (see
:ref:`Event Notifications`), and contain the relevant payload in the
:js:data:`notification_data` attribute.


Put Complete Notification
-------------------------

This notification is generated when put is complete for the expectation. This
notification has the consolidated data for all successful and unsuccessful
transactions in the put process for a service request.

The payload for this notification has the complete :ref:`Service Request Object`
with all transactions populated as :js:data:`container`\ s in the
:js:data:`actuals` attribute.

.. container:: toggle

   .. container:: header

      **Sample JSON**:
   
   .. literalinclude:: put/put_complete_notification.json
      :language: JSON


Put Exception Notifications
---------------------------

These notifications are generated whenever there is any user or system generated
exception in the put process flow. It is usually not necessary to subscribe to
these notifications because the final put complete notifications contain details
about all exceptions that occurred in that service request.

.. list-table::
   :header-rows: 1
   :widths: 30, 15, 55

   * - Exception
     - Location
     - Sample JSON

   * - Item Unscannable
     - Put Back
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/item_unscannable_put_back_notification.json
             :language: JSON

   * - Physically Damaged
     - Put Back
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/physically_damaged_put_back_notification.json
             :language: JSON

   * - Item Oversized
     - Put Back
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/item_oversized_put_back_notification.json
             :language: JSON

   * - Extra Items
     - Put Back
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/extra_items_put_back_notification.json
             :language: JSON

   * - Warehouse Full
     - Put Back
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/warehouse_full_put_back_notification.json
             :language: JSON

   * - Physically Damaged
     - Put Front
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/physically_damaged_put_front_notification.json
             :language: JSON

   * - Unscannable / Missing
     - Put Front
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/unscannable_missing_put_front_notification.json
             :language: JSON

   * - Extra Items
     - Put Front
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/extra_items_put_front_notification.json
             :language: JSON

   * - Warehouse Full
     - Put Front
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/warehouse_full_put_front_notification.json
             :language: JSON

   * - Space Unavailable
     - Put Front
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/space_unavailable_put_front_notification.json
             :language: JSON


Put Staging Notifications
-------------------------

In the cases when put process' staging is controlled via API (instead of
manually), these extra notifications can be generated.

.. list-table::
   :header-rows: 1
   :widths: 30, 70

   * - Event
     - Sample JSON

   * - Staging Success
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/staging_success_notification.json
             :language: JSON

   * - Staging Failure
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/staging_failure_notification.json
             :language: JSON

   * - Staging Cancelled
     - .. container:: toggle
       
          .. container:: header
       
             Show/Hide
          
          .. literalinclude:: put/staging_cancelled_notification.json
             :language: JSON