@startuml
title <size:18>__ U2.0 Prepaid Upgrade + ML - Warranty Exchange __</size>
actor Rep
participant Rep as Rep
participant Rebellion as UI
participant Ingenico as Ingenico
participant APIGateway as APIGateway
participant ES as ES
participant ESP as ESP
participant WSIL as WSIL
participant ElasticSearch as ElasticSearch

note over UI: Entry to the flow from Line Details page (SC1111)
== Determine Warranty Exchange & Override eligibility ==
UI->APIGateway : API_2911(286)_getWarrantyExchange(MSISDN, IMEI)
APIGateway->ES : API_2911(286)_getWarrantyExchange(MSISDN, IMEI)
ES->WSIL : DeviceWSIL.checkExchangeEligibility
WSIL-->ES : Response DeviceWSIL.checkExchangeEligibility
ES-->APIGateway: Response API_2911(286)_getWarrantyExchange(MSISDN, IMEI)
APIGateway-->UI: Response API_2911(286)_getWarrantyExchange(MSISDN, IMEI)

note over UI: Based on the warranty status

alt If warrantyStatus= NOTFOUND
note over UI: Device information was not found or no associated imei was found for msisdn
UI-> UI : Do not display Warranty Blade
end

alt If warrantyStatus= HARDSTOP
note over UI: Not eligible and cannot be overriden
UI-> UI : Disable Warranty blade with “>” blade
end

alt If warrantyStatus= OVERRIDE
note over UI: Not eligible (Perm ID:235) but can be overridden
UI -> UI : Enable Warranty blade with lock icon with message about eligibility
Rep -> UI: On click of Lock icon, display Supervisor login and password textboxes
UI -> APIGateway: API_233_postRepVerification(two step process- get transaction Id and pass it next request)
APIGateway -> ES : API_233_postRepVerification
ES -> APIGateway: Response API_233_postRepVerification
APIGateway -> UI: Response API_233_postRepVerification
end

==  1. Order summary ==
UI->APIGateway: API_2912_getDeviceStaticData(IMEI,SKU)
APIGateway->ES: API_2912_getDeviceStaticData(IMEI,SKU)
ES->ElasticSearch:  Elastic search generic request
ElasticSearch-->ES: Complete Elastic Search response
note over ES: ES will iterate over Elastic search response and provide the device image and details
ES-->UI: API_2912_getDeviceStaticData Response(image, device details)
Note over UI: On click of Continue CTA \n navigate to Validate Device blade

==  2. Validate device & Assess item (Questions) ==
UI -> APIGateway: API_240_getDeviceAssessmentQuestions(type,ResponseMode)
APIGateway -> ES: API_240_getDeviceAssessmentQuestions(type,ResponseMode)
ES -> WSIL: OrderReferenceDataWSIl.getDeviceAssessmentQuestions
WSIL -->ES: Response OrderReferenceDataWSIL Response
ES --> APIGateway : Response API_240_getDeviceAssessmentQuestions(type,ResponseMode)
APIGateway --> UI: Response API_240_getDeviceAssessmentQuestions(type,ResponseMode)
Rep -> UI: After questions answered and on click of Continue CTA
UI -> APIGateway: API_2128 (477)-POST /carts/{cartID}/lines/{lineID}/warranty (orderType="EXCHANGE" and reason="WARRANTY")
APIGateway -> ES: API_2128 (477)-POST /carts/{cartID}/lines/{lineID}/warranty (orderType="EXCHANGE" and reason="WARRANTY")
ES -> WSIL: CartWSIL.updateCart(orderType="EXCHANGE" and reason="WARRANTY")
WSIL -->ES: Response cart response(cartId, reportingAnswer)
ES --> APIGateway: Response API_2128 cart response(cartId, reportingAnswer)
APIGateway --> UI: Response API_2128 cart response(cartId, reportingAnswer)

==  4. Select reason ==
Note over UI: Pass the type based on the scenario(to get reasons)
UI -> APIGateway: API_326_getReasons(type)
APIGateway -> ES: API_326_getReasons(type)
ES -> WSIL : OrderReferenceDataWSIL.getReasons
WSIL --> ES : Response OrderReferenceDataWSIL.getReasons
ES --> APIGateway: Response API_326_getReasons(type)
APIGateway --> UI : Response API_326_getReasons(type)

note over Rep : Rep selects a reason
Rep->UI: reason selected
UI->APIGateway: API_2128-Post(477) /carts/{cartID}/lines/{lineID}/warranty (orderType="EXCHANGE" and reason="WARRANTY")
APIGateway->ES: API_2128-Post(477) /carts/{cartID}/lines/{lineID}/warranty (orderType="EXCHANGE" and reason="WARRANTY")
ES-> WSIL: CartWSIL.updateCart(orderType="EXCHANGE" and reason="WARRANTY")
WSIL-->ES: Response cart response
ES-->APIGateway: Response API_2128 cart response
APIGateway-->UI: Response API_2128 cart response

==  5. Select replacement device ==
UI -> APIGateway: API_302_getSuggestedExchangeProducts
APIGateway -> ES: API_302_getSuggestedExchangeProducts
ES -> WSIL : ProductOfferingSummaryWSIL.getReplacementKitOrDevice
WSIL --> ES : Response ProductOfferingSummaryWSIL.getReplacementKitOrDevice
ES --> APIGateway: Response API_302_getSuggestedExchangeProducts
APIGateway --> UI : Response API_302_getSuggestedExchangeProducts

Rep->UI: Item selected
note over UI : upon Item selection, cart is updated to have 2nd item actionCode=add
UI->APIGateway: API_2128-Post(477) /carts/{cartID}/lines/{lineID}/warranty
APIGateway->ES: API_2128-Post(477) /carts/{cartID}/lines/{lineID}/warranty
ES-> WSIL: CartWSIL.updateCart
WSIL-->ES: Response cart response
ES-->APIGateway: Response API_2128 cart response
APIGateway-->UI: Response API_2128 cart response

==  6. Cart review ==
note over UI: Previous call to cart \n will load the cart review
alt User select Remove CTA
UI->APIGateway: API_2128-Post(477) /cart/@actionCode = REMOVE
APIGateway->ES: API_2128-Post(477) /cart/@actionCode = REMOVE
ES-> WSIL: CartWSIL.updateCart
WSIL-->ES: Response cart response
ES-->APIGateway: Response API_2128 cart response
APIGateway-->UI: Response API_2128 cart response
end

Rep -> UI : Click on Checkout CTA

==  7. Shipping address & Submit Order ==
UI->APIGateway: API 196-getShippingOptions
APIGateway->ES: API 196-getShippingOptions
ES-> WSIL: CartWSIL.getShippingOptions
WSIL-->ES: Response CartWSIL.getShippingOptions
ES-->APIGateway: Response API 196-getShippingOptions
APIGateway-->UI: Response API 196-getShippingOptions

alt  New Shipping Address
Rep -> UI : "New Address" radio button selected

UI->APIGateway: API_2004_validateAddress
APIGateway->ES: API_2004_validateAddress
ES-> WSIL: AddressWSIL.ValidateAddress
WSIL-->ES: Response AddressWSIL.ValidateAddress
ES-->APIGateway: Response API_2004_validateAddressr
APIGateway-->UI: Response API_2004_validateAddress
end

UI->APIGateway: API_2120__cartCheckout (shipping Info fields)
APIGateway->ES: API_2120__cartCheckout (shipping Info fields)
ES-> WSIL: CartWSIL.updateCart
WSIL -->ES: Response CartWSIL.updateCart
ES--> APIGateway: Response API_2120__cartCheckout
APIGateway-->UI: Response API_2120__cartCheckout

UI->APIGateway: API_2120__cartCheckout ((checkout fields))
APIGateway->ES: API_2120__cartCheckout ((checkout fields))
ES-> WSIL: CartWSIL.updateCart
WSIL -->ES: Response CartWSIL.updateCart
ES--> APIGateway: Response API_2120__cartCheckout
APIGateway-->UI: Response API_2120__cartCheckout

alt channel = retail
note over UI : Ingenico integration required
Rep -> UI: Rep clicks on **Send T&C to Ingenico**
UI->APIGateway: API_2806_termsAndConditions
APIGateway->ES: API_2806_termsAndConditions
ES-> WSIL: CustomerDocumentWSIL.getDocumentReference
WSIL -->ES: Response CustomerDocumentWSIL.getDocumentReference
ES--> APIGateway: Response API_2806_termsAndConditions
APIGateway-->UI: Response API_2806_termsAndConditions
note over UI : send received T&Cs to Ingenico device
UI --> Ingenico : Response API_2806_termsAndConditions
end

alt channel = Care
Rep -> UI: Show T&Cs

UI->APIGateway: API_2806_termsAndConditions
APIGateway->ES: API_2806_termsAndConditions
ES-> WSIL: CustomerDocumentWSIL.getDocumentReference
WSIL -->ES: Response CustomerDocumentWSIL.getDocumentReference
ES--> APIGateway: Response API_2806_termsAndConditions
APIGateway-->UI: Response API_2806_termsAndConditions
Rep -> UI: Rep clicks on **Accept T&C**
end

Rep -> UI: Continue CTA
note over UI : cart set to checkput mode \n updated Shipping Address, Shipping Option and Shipping Notification preference.

UI->APIGateway: API_2150_submitOrder
APIGateway->ES: API_2150_submitOrder
activate ES
ES-> ESP: API_372_postUpdateOrderPaymentMethod \n (transactionType = "WarrantyExchange", empty payment object) \n OrderUpdateWSIL.submitOrder
ESP --> ES : Response OrderdID
ES-> ESP: API_340_postCreateOrder(OrderId) \n OrderCheckoutEnterprise.confirmOrderCheckout
ESP --> ES : Response Confirmation with OrderId
ES-->APIGateway: Response API_2150_submitOrder
deactivate ES
APIGateway-->UI: Response API_2150_submitOrder

UI->APIGateway: API_2814_orderDetails (orderId)
APIGateway->ES: API_2814_orderDetails (orderId)
ES-> WSIL: OrdereWSIL.getOrderDetails
WSIL-->ES: Response OrderWSIL.getOrderDetails
ES-->APIGateway: Response API_2814_orderDetails
APIGateway-->UI: Response API_2814_orderDetails

@enduml