'See http://plantuml.com/sequence-diagram for details on how to create Sequence Diagrams in PlantUML'
@startuml

center header
<font size=32>Plans Overview - TO BE</font>
endheader

actor "Customer \n on \n Web or Mobile" as Customer
participant "AEM Publisher\n Templates Servlet" as AEM

box "API Gateway"
participant "Apigee" as Apigee
end box
box "Aggregation/Orchestration Tier \n // Aggregate Capabilities for all Clients/Channels//" #LightGreen
'Not proven to be needed yet:   participant "Subscribers\n  Aggregation\n GET Microservice" as Subscribers
   participant "AccountPlans\n GET Microservice\n ([[http://flows.corporate.t-mobile.com/all-swaggers/swagger/ce.dsg.bd/recurring-items.yaml/ swagger]])" as GetPlans
'   participant "AccountPlans\n PATCH Microservice" as PlansPatch
'   participant "PlanEstimates\n POST Microservice" as Estimates
'   participant "Eligible \n Products\n Microservice" as EligibleProducts
end box
box "Capabilities Tier \n// Provide Business Functionality //"
   participant "MPM\n RatePlans\n ([[http://flows.corporate.t-mobile.com/all-swaggers/swagger/ce.dsg.ps/ps-rateplan-service.json/ swagger]]/[[https://developer.t-mobile.com/prod-reference#Product-and-Service_PS-Rateplan-Service/operation/getRateplans api]])" as MPMRatePlans
   participant "MPM\n Services\n ([[http://flows.corporate.t-mobile.com/all-swaggers/swagger/ce.dsg.ps/ps-service-service.json/ swagger]]/[[https://developer.t-mobile.com/prod-reference#Product-and-Service_PS-Service-Service/operation/getServices api]])" as MPMServices
   participant "MPM\n Promotions\n ([[http://flows.corporate.t-mobile.com/all-swaggers/swagger/ce.dsg.ps/ps-promotion-service.json/ swagger]]/[[https://developer.t-mobile.com/prod-reference#Product-and-Service_PS-Promotion-Service/operation/getPromotions api]])" as MPMPromos
   participant "MPM\n Devices\n ([[http://flows.corporate.t-mobile.com/all-swaggers/swagger/ce.dsg.ps/ps-device-service.json/ swagger]]/[[https://developer.t-mobile.com/prod-reference#Product-and-Service_PS-Device-Service/operation/getDevices api]])" as MPMDevices
   participant "EIP\n Loan\n ([[http://flows.corporate.t-mobile.com/swagger/ce.cfs.loans.ls/CFS-getLoanHistory.json swagger]])" as EIPLoan
   participant "EIP\n Lease\n ([[http://flows.corporate.t-mobile.com/swagger/ce.cfs.lease.ls/CFS-getLeaseDetails.json swagger]])" as EIPLease
   participant "EIP\n Device Promo\n ([[http://flows.corporate.t-mobile.com/swagger/ce.dd.bd.eip/LoanPromotionAwardProfile.json swagger]])" as EIPDevicePromo
   participant "[[{Hosted in Cassandra} Service\n Agreements]]\n(swagger)" as ServiceAgreements
   participant "Reference \n SOCs\n(swagger)" as SOCs
   participant "[[{Hosted in Gemfire} Discounts]]\n(swagger)" as Discounts
   participant "Subscribers\n(swagger)" as Subscribers
   participant "Billing\n Account\n(swagger)" as BillingAccount
   participant "Union\n(swagger)" as EIR
end box
   participant "DEEP.io" as Deep
   participant Tibco
   participant "AEM \n Digital Asset\n Manager (DAM)" as DAM
   participant "Tuxedo / \n Samson" as Samson

Samson -> Deep: // Discounts Changed Event //
activate Deep
Deep -> Discounts
deactivate
Samson -> Deep: // ServiceAgreement Changed Event //
activate Deep
Deep -> ServiceAgreements
'ServiceAgreements
deactivate

Customer -> AEM: // **On Site 1st Page visit** //
activate Customer
activate AEM
AEM --> Customer: Return MyTMO Single Page App\n //consider caching for ~24+hrs?//
deactivate
Customer -> DAM: Get Assets
activate DAM
DAM --> Customer: // Assets //
deactivate DAM
deactivate Customer

== Plans Overview ==
Customer -> AEM:[[https://bitbucket.corporate.t-mobile.com/users/nsyfrig1/repos/eservice_foundational/browse/core/servlet/src/main/java/com/mytmobile/servlets/GetSessionDetailServlet.java#57 GetSessionDetailServlet ~330ms]]
activate Customer
Activate AEM
AEM --> Customer: isPAHPresent, msisdn, ban, jsession, accountType, accountSubType, userRole, \n isTMOApp, customerType, isOnboardingOn, defaultTMOID
Deactivate AEM

Customer -> GetPlans: //**On Site Visit & click Plans Tab: ** // \n - On Site visit, prefetch & cache response for ~5mins, \n - On SPA load, if not expired & prefetched, use from \n     cache w/o invalidation check\n GET /v1/accountPlans/

activate GetPlans
GetPlans -> ServiceAgreements: // Get ServiceAgreements //
GetPlans -> Subscribers: // GET /v1/subscribers/{MSISDN?}
GetPlans -> BillingAccount: // GET (need swagger)
activate Subscribers
activate ServiceAgreements
activate BillingAccount
alt On first request for BAN
ServiceAgreements -> Samson: // Retrieve for BAN //
activate Samson
Samson --> ServiceAgreements: // Service Agreement //
deactivate Samson
end alt
ServiceAgreements --> GetPlans: Service Agreements
deactivate ServiceAgreements
BillingAccount --> GetPlans: accountType, accountSubType, accountStatus, accountStatusReasonCode, autoPayStatus, billingAddressStateCode
deactivate BillingAccount
alt For all equipment purchased on Installment
GetPlans -> EIPLoan
activate EIPLoan
EIPLoan ->] : ([[http://flows.corporate.t-mobile.com/all-diagrams/sequence_diagrams/bd/ce.dd.bd.eip.create.poip.event.puml/ diagram]])
EIPLoan --> GetPlans
deactivate EIPLoan
end alt
alt For all equipment on Lease on account
GetPlans -> EIPLease
activate EIPLease
EIPLease ->] : ([[http://flows.corporate.t-mobile.com/all-diagrams/sequence_diagrams/bd/ce.dd.bd.eip.create.lease.event.puml/ diagram]])
EIPLease --> GetPlans
deactivate EIPLease
end alt
GetPlans -> SOCs: // Fetch Reference SOCs //
activate SOCs
GetPlans -> EIPDevicePromo: Get Equipment Promotion Pricing
activate EIPDevicePromo
EIPDevicePromo ->] : ([[http://flows.corporate.t-mobile.com/all-diagrams/sequence_diagrams/bd/ce.dd.bd.loan.promotion.award.profile.puml/ diagram]])
GetPlans -> Discounts: Get Discounts on Account/Line
activate Discounts
GetPlans -> MPMRatePlans: get /products/v1/rateplans
activate MPMRatePlans
GetPlans -> MPMRatePlans: get /products/v1/services
GetPlans -> MPMRatePlans: get /products/v1/promotions
GetPlans -> MPMRatePlans: get /products/v1/devices
GetPlans -> EIR: get IMEI for equipment on Network
activate EIR
SOCs --> GetPlans: // SOCs: Classifications, Indicators, Attributes //
Subscribers --> GetPlans: // line.type, product.type, line.statusCode, line.statusReasonCode  //
deactivate Subscribers
deactivate SOCs
EIPDevicePromo --> GetPlans: // Device Promotion Price //
deactivate EIPDevicePromo
Discounts --> GetPlans: // Discounts //
deactivate Discounts
MPMServices --> GetPlans: // Services catalog entries //
MPMPromos --> GetPlans: // Promotions catalog entries //
MPMRatePlans --> GetPlans: // Plans catalog entries //
deactivate MPMRatePlans
EIR --> GetPlans: // IMEIs on Account Lines //
deactivate EIR

GetPlans --> Customer: // AccountPlans //
deactivate
deactivate Customer


Customer -> MPMDevices: get /products/v1/devices
activate MPMDevices
MPMDevices --> Customer: // Specs of Device On Network // \n get 1st time, cache long-term in browser
deactivate MPMDevices

alt Device not found in MPM Devices: Display default Device shadow
end alt

Customer -> DAM: // GET Device Images //
activate DAM
DAM --> Customer: // Device Images // \n get 1st time, cache long-term in browser
deactivate DAM
deactivate Customer

'== Plan Detail (no additional data calls identified so far) ==
'Customer --> Customer : // Drill into plan details //
'
'== Choose Plan ==
'Customer -> Estimates: // ** Clicks "Change Plans" CTA ** // [This is really change primary Voice Plan, right?] \n POST /estimates/${BAN}
'Activate Customer
'Activate Estimates
'Estimates -> GetPlans: // Get current Account Plan //
'activate GetPlans
'GetPlans --> Estimates: - User Type [Pooled|SL|Multiline|Non-pooled] \n- AALs on current plan
'deactivate GetPlans
'Estimates -> EligibleProducts: GET /products/plans?${BAN}
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/UprisingR1.6/sid/html/GetPlanSelection.html#GetPlanSelectionOperation GetPlanSelection]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/UprisingR1.6/TibcoProcess-Enterprise_Services_Subscriber_GetPlanSelectionSvc.process-detail.html GetPlanSelectionSvc]]
'activate Samson
'Samson --> Tibco: // Eligible Plans //
'deactivate Samson
'Tibco --> Estimates: // Eligible Plans //
'deactivate Tibco
'Estimates --> Estimates: // Configure eligible Plans //\n// w/ existing AALs, EIPs, AddOns //\n// and calc sums //
'Estimates --> Customer:  // Return array of preconfigured possible AccountPlans //
'deactivate Estimates
'Customer -> Customer:    // Render Plan Comparison/Diff //
'deactivate Customer
'
'
'== Configure Plan ==
'Customer -> Customer: // ** Selects a Plan ** // \n // SPA builds list of plan deltas //
'activate Customer
'activate EligibleProducts
'Customer -> EligibleProducts: POST /eligible-products/addons/ {BAN} & NEW-PLAN-SOC
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/CustomerPlanService.html#getEligibleServices GetEligibleServices]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Implementations_LegacyESOA_CustomerPlan_GetEligibleServicesImpl.process-detail.html GetEligibleServicesImpl]]
'activate Samson
'Samson --> Tibco: // Eligible Add-Ons //
'deactivate Samson
'Tibco --> EligibleProducts: // Eligible Add-Ons //
'deactivate Tibco
'EligibleProducts --> Customer: // Eligible Add-Ons //
'deactivate EligibleProducts
'
'Customer -> EligibleProducts: POST /eligible-products/datapasses/ {BAN} & NEW-PLAN-SOC
'activate EligibleProducts
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/ServiceProductsLookup.html#GetEligibleDataPasses GetEligibleDataPasses]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Enterprise_Services_Product_GetEligiblePrepaidRatePlanSvc.process-detail.html GetEligiblePrepaidRatePlanSvc]]
'activate Samson
'Samson --> Tibco: // Eligible Data Passes //
'deactivate Samson
'Tibco --> EligibleProducts: // Eligible Data Passes //
'deactivate Tibco
'EligibleProducts --> Customer: // Eligible Data Passes //
'deactivate EligibleProducts
'
'Customer -> EligibleProducts: POST /eligible-products/eips/ {BAN} & NEW-PLAN-SOC
'activate EligibleProducts
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/SubscriberLookup.html#GetSocParameter GetSOCParameter]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Enterprise_Services_Subscriber_GetSocParameterSvc.process-detail.html GetSocParameterSvc]]
'activate Samson
'Samson --> Tibco: // Rules on Channel Parity //
'deactivate Samson
'Tibco --> EligibleProducts: // Rules on Channel Parity ? //
'deactivate Tibco
'EligibleProducts --> Customer: // Rules on Channel Parity ? //
'deactivate EligibleProducts
'
'Customer -> EligibleProducts
'activate EligibleProducts
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/Installment.html#GetSubscribersEIPPlans GetSubscribersEIPlans]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Enterprise_Services_Installment_GetSubscribersEIPPlansSvc.process-detail.html GetSubscribersEIPPlansSvc]]
'activate Samson
'Samson --> Tibco: // Equipment Investment Plan //
'deactivate Samson
'Tibco --> EligibleProducts: // Equipment Investment Plan //
'deactivate Tibco
'EligibleProducts --> Customer: // Equipment Investment Plan //
'deactivate EligibleProducts
'
'Customer -> EligibleProducts
'activate EligibleProducts
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/CustomerPlanService.html#getServiceChangeEffectiveDates GetServiceChangeEffectiveDates]]
'activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Implementations_LegacyESOA_CustomerPlan_GetServiceChangeEffectiveDatesImpl.process-detail.html GetServiceChangeEffectiveDatesImpl]]
'activate Samson
'Samson --> Tibco: // Back/Future date for Plan/Service //
'deactivate Samson
'Tibco --> EligibleProducts: // Back/Future date for Plan/Service //
'deactivate Tibco
'EligibleProducts --> Customer: // Back/Future date for Plan/Service //
'deactivate EligibleProducts
'
'deactivate EligibleProducts
'Customer --> Customer: // Rendered Plans Configure Page //
'deactivate Customer

'== Change Plan ==
'' HTTP Patch: https://stackoverflow.com/questions/28459418/rest-api-put-vs-patch-with-real-life-examples
'Customer -> Customer: // ** Hits "Agree and Submit" **// \n patch /accounts/$BAN { "voicePlan": { "name": "newPlanSOC" } }
'Activate Customer
'Customer -> EligibleProducts
'Activate EligibleProducts
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/CustomerPlanService.html#validatePlanAndServices validatePlanAndServices]]
'Activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Implementations_LegacyESOA_CustomerPlan_ValidatePlanAndServicesImpl.process-detail.html ValidatePlanAndServicesImpl]]
'Activate Samson
'Samson --> Tibco: // Success or reasons why invalid //
'Deactivate Samson
'Tibco --> EligibleProducts: // Success or reasons why invalid //
'Deactivate Tibco
'EligibleProducts -> Tibco: [[https://servicecatalog.internal.t-mobile.com/servicecat/tibco/2018-03-24/sid/html/CustomerPlanService.html#changePlanAndServices changePlanAndServices]]
'Activate Tibco
'Tibco -> Samson: [[https://servicecatalog.internal.t-mobile.com/servicecatworkflow/tibco/2018-03-24/TibcoProcess-Implementations_LegacyESOA_CustomerPlan_ChangePlanAndServicesImpl.process-detail.html ChangePlanAndServicesImpl]]
'Activate Samson
'Samson --> Tibco: // Success or reason for failure //
'Deactivate Samson
'Tibco --> EligibleProducts: // Success or reason for failure //
'Deactivate Tibco
'EligibleProducts --> Customer: // Success or reason for failure //
'Deactivate EligibleProducts
'Deactivate Customer
'
'== Line Detail  (no calls, data already fetched) ==
'
'== Change Add Ons ==
'Customer -> PlansPatch: // ** Add Account-level Service ** // \n patch /accounts/$BAN { "services": [{ "name": "Netflix" }] }
'Customer -> PlansPatch: // ** Add Line-level Service ** // \n patch /accounts/$BAN/lines/$MSISDN { "services": [{ "name": "International Roaming" }] }

center footer
    <font size=16>version: INITIAL DRAFT</font>
endfooter

@enduml
