@startuml
title  Accessory Sort and Filter
participant "Rebellion UI" as UI
participant "API Gateway" as GW
participant "Experience Services" as ES
participant "Experience Services Cache" as ESCH
participant "Elastic Search" as ESES
participant "CAAS" as CAAS
participant "WSIL" as WSIL
participant "IAM" as IAM

/'****************************************************'/
note over UI: Rebellion Application is initialized

UI->UI: Initiate Browse Accessories by clicking on Shop - Accessories


note over UI
Browse accessories landing page
end note

UI -> GW : API_2166_getProductCategories
GW -> ES : API_2166_getProductCategories

note over ES
Retrieve: Retrieve Categories
end note
 ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
ES <-- WSIL

note over ES
Sort: Sort Categories A-Z
Caching: Cache sorted Categories
end note

ES -> ESCH : Cache Sorted Categories
ES <-- ESCH

note over ES
Retieve first 3 categories, paralelly
end note
    
ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
ES <-- WSIL
ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
ES <-- WSIL
ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
ES <-- WSIL

ES -> ES : API_2154 retriveProductInventor
ES -> CAAS: getInventoryStatus
ES <-- CAAS:
ES <-- ES

loop if any of the first 3 categories do not have active products and category list has more items to be processed

	alt all categories do not have any products
		note over ES
		Retieve next 3 categories, paralelly
		end note
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
	end
	alt 2 categories do not have any products
		note over ES
		Retieve next 2 categories, paralelly
		end note
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
	end
	alt one category does not have any products
		note over ES
		Retieve next 1 category
		end note
		ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
		ES <-- WSIL
	end
	ES -> ES : API_2154 retriveProductInventor
	ES -> CAAS: getInventoryStatus
	ES <-- CAAS:
	ES <-- ES
end 
note over ES
Merge response
end note

GW <-- ES
UI <-- GW

alt Scroll Down Without Condition Change
	note over UI
	Browse accessories landing page, scroll down for more categories
	end note
	
	UI -> GW : API_2166_getProductCategories
	GW -> ES : API_2166_getProductCategories
	ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
	ES <-- WSIL
	
	note over ES
	Sorting: Sort Categories A-Z regarding to
	Category Name
	end note
	 ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
	ES <-- WSIL
	
	note over ES
	Caching: Cache sorted Categories
	end note
	
	ES -> ESCH : Cache Sorted Categories
	ES <-- ESCH
	
	note over ES
	Retieve first 3 categories, paralelly
	end note
      
      ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
	ES <-- WSIL
	ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
	ES <-- WSIL
	ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
	ES <-- WSIL
	ES -> ES : API_2154 retriveProductInventor
	ES -> CAAS: getInventoryStatus
	ES <-- CAAS:
	ES <-- ES
	loop if any of the 3 categories do not have active products and category list has more items to be processed
		alt all categories do not have any products
			note over ES
			Retieve next 3 categories, paralelly
			end note
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
		end
		alt 2 categories do not have any products
			note over ES
			Retieve next 2 categories, paralelly
			end note
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
		end
		alt one category does not have any products
			note over ES
			Retieve next 1 category
			end note
			ES -> WSIL : ProductOfferingSummaryWSIL.getCatalogPriceData
			ES <-- WSIL
		end
		ES -> ES : API_2154 retriveProductInventor
		ES -> CAAS: getInventoryStatus
		ES <-- CAAS:
		ES <-- ES
	end
	note over ES
	Merge response
	end note
	
	GW <-- ES
	UI <-- GW
end
@enduml