@startuml
'diagram parameters'
autonumber
'skinparam dpi 300
skinparam LegendBackgroundColor #white

'diagram title'
title PB-361 UC2 - Get credit card offer eligibility

'a list of the actors and participants'
actor "Next Customer" as UI
box "Next Platform"
participant "Core Next" as Next
database "Next Database" as DB
participant "getAvailableChangePlans service" as CP
end box
'participant "FCOD API" as FCOD
participant "CALE API" as CALE

'a brief description of the diagram'
legend top
-- \t**Abstract:**\t --
This PB goal is to offer international credit card to customer who don't have any
credit products and that were not approved on previous credit analysis.

This new endpoint will check if the customer is eligible to this new credit card
offer
If the customer already has a credit card, or doesn't have , coreNext should not
offer a new one.

In order to offer a add a new product to customer's plan, we need to run the
change Plan flow. Otherwise, we will impact currently existing change plan.
This diagram wil call  GET /changePlans at some point, since we should run exactly
same logic
We should handle GET /changePlans response before sending it to the app layer, to
remove all plans and products that are not part of this PB.

This endpoint will be used to present screen NC_CT_A1_05
end legend


UI -> Next: GET /v1/creditLine/eligibility?customerId={customerId}&products[]=creditCard
activate Next

note left of Next #plum
**Endpoint:**
This endpoint will check if given customer is eligible to a new credit card offer.
If so, a new proposal will be created by calling already existing
""getAvailableChangePlans"" service and an credit card offer screen will be
presented on the app layer

**Current implementation:**
This is a new endpoint

''**Required implementation:**
**Request:**
customerId - required
products= [1] (creditCard)

**Response:**
Response will be same as in GET /changePlans plus a couple of fields that will
be used by the app to decide whether presente
or not the offer screen.
""{""
""  "offerId": Integer""
""  "isEligibleToNewCreditCardOffer": Boolean""
""  "approvedAmount": Double""
""  "listOfPlans": [""
""    {""
""      "listOfProducts": [""
""        {""
""          "productCode": 0,""
""          "productDetail": {""
""            "listOfValidInvoiceDay": [""
""              {""
""                "cardExpirationDay": 0""
""              }""
""            ]""
""          },""
""          "productSummaryDescription": "string",""
""          "productTermEndDate": "2019-04-01",""
""          "productTermStartDate": "2019-04-01",""
""          "productType": 0,""
""          "servicePackageDetail": {""
""            "listOfComponents": [""
""              {""
""                "componentGroup": 0,""
""                "componentIndicator": 0,""
""                "componentRate": 0,""
""                "componentRateAmount": 0,""
""                "exemptIndicator": 0,""
""                "finalIndividualRateTerm": "string",""
""                "finalTermComponent": "string",""
""                "franchiseReverseIndicator": "string",""
""                "indicadorObrigatoriedade": "string",""
""                "initialIndividualTermRate": "string",""
""                "initialTermComponent": "string",""
""                "maxFranchiseComponentRate": 0,""
""                "maxFranchiseGroupRelated": 0,""
""                "maxFranchiseComponentGroup": 0,""
""                "minFranchiseComponentGroup": 0,""
""                "minFranchiseComponentRate": 0,""
""                "minRelatedFrachiseGroup": 0,""
""                "relatedGroup": 0,""
""                "secondLineOfBankStatement": "string" ""
""              }""
""            ],""
""            "servicePackageStatus": 0,""
""            "servicePackageTermEndDate": "2019-04-01",""
""            "servicePackageTermStartDate": "2019-04-01""
""          },""
""          "supportCredit": "string",""
""          "value": 0""
""        }""
""      ],""
""      "name": "string",""
""      "planFreePeriod": "string",""
""      "planTermEndDate": "2019-04-01",""
""      "planTermStartDate": "2019-04-01",""
""      "productGroupCode": 0,""
""      "productGroupDescription": "string",""
""      "productGroupStatus": 0,""
""      "supportCredit": true,""
""      "value": 0""
""}""

  **ENSURE BACKWARDS COMPATIBILITY IS MAINTAINED**
  end note

  note right of Next #orange
  **Note to Developers**
  **ACTION REQUIRED: Create new parameters on "APPLICATION_PARAMETER" table**:
  (Names below are just asuggestion.)

  * CREDIT_CARD_OFFER_SCREEN_ENABLED, default 'True'; Flag created for PB-361 that
  will be used to enable/disable the screen to present a new credit card offer to
  the customer after the login screen;

''  2. CREDIT_CARD_ACTIVATION_SCREEN_ENABLED, default 'True'; Flag created for PB-361 that will be used to enable/disable the screen to ask the customer to
''  activate a credit card after the login screen;

  * DAYS_TO_PRESENT_CREDIT_CARD_OFFER_AFTER_DECLINED, value 30; Parameter created
  for PB-361 to control the amount of **days** that the app will wait, after
  a customer declined the offer, to present the credit card offer screen again.

''  4.DAYS_TO_PRESENT_CREDIT_CARD_ACTIVATION_AFTER_DECLINED, value 1; Parameter created for PB-361 to control the amount of **days** that the app will wait, after
''  a customer declined the activation screen, to present the credit card activation screen again.

  * Create credit_product table.
  credit_product_uid: integer not null(pk),
  customer_uid:integer not null (fk to customer table),
  proposal_uid integer nullable (fk to proposal table),
  credit_product_offer_notification_dt timestamp not null
  credit_product_create_dt date nullable,
  credit_product_type decimal(1) not null [1 = creditCard]
  credit_decision_code number(1) nullable (1 - approved, 2 not approved on credit anaylsis),
  approved_credit_amt Number(18,2) nullable,
  credit_product_declined_dt date nullable,
  credit_product_accept_dt date nullable,
  credit_card_activation_dt date nullable
  enable_ind varhcar2(1) not null. [T = true/activated and F = False/deactivated]
  end note

'' activation  Next -> DB: **SQL** \n select PARAMETER_NAME, PARAMETER_VALUE from APPLICATION_PARAMETER where PARAMETER_NAME  in ('CREDIT_CARD_OFFER_SCREEN_ENABLED', \n 'CREDIT_CARD_ACTIVATION_SCREEN_ENABLED', DAYS_TO_PRESENT_CREDIT_CARD_ACTIVATION, DAYS_TO_PRESENT_CREDIT_CARD_OFFER)


alt customerId is null
  Next-->UI: HttpStatus 400 (Bad Request)
  note left of Next #coral
  **Clarification:**
  Do we need a custom message in this scenario? Since in this case the screen
  shouldn't be presented

  Suggested message: "CustomerId was not informed.""

  **Answer:** Use suggested message;

  end note
end alt

alt product is null OR is not creditCard
  Next-->UI: HttpStatus 400 (Bad Request)
  note left of Next #coral
  **Clarification:**

  Do we need a custom message in this scenario? Since in this case the screen
  shouldn't be presented
  Suggested message: "product was not informed or is an invalid product.""

    **Answer:** Use suggested message;
  end note
end alt

 Next -> DB: **[query 1]** \n select PARAMETER_NAME, PARAMETER_VALUE\n  from APPLICATION_PARAMETER\nwhere PARAMETER_NAME \n\tin ('CREDIT_CARD_OFFER_SCREEN_ENABLED', DAYS_TO_PRESENT_CREDIT_CARD_OFFER)
  activate DB

  DB --> Next: response
  deactivate DB

  note left of DB
  Retrieve all parameters that will be used in the diagram, to avoid multiple
  accesses to the database.
  end note


  alt CREDIT_CARD_OFFER_SCREEN_ENABLED = false

    Next--> UI: HttpStatus 422. (unprocessable Entity)\n Nothing should be presented by the app.

    note left of Next #coral
    **Clarification:**
    Do we need a custom message in this scenario?
    Since in this case the screen shouldn't be presented

    Suggested message: Offer screen option is not enabled
      **Answer:** Use suggested message;
    end note

  end alt


''        Next -> DB: **SQL**\n update credit_product_offers \n  SET enable_ind = 'F'\n where customer_uid = customerId\n and ENABLE_IND = true\n and credit_product_offer_creation_dt is NOT null \n and credit_product_offer_creation_dt < today\n AND credit_product_offer_accept_dt is null \n and credit_product_type = [creditCard]
''        activate DB
''
''        note right of Next #orange
''        **Technical Note:**
''        We should only deactivate offers that were created in the past and have
''        credit_product_create_dt. This field indicates that the customer had ran
''        throught eligibility use case.
''        If an offer only has ""customer_uid"" and ""product_type"", it means that
''        the customer received a notification from NBA but haven't went throught
''        eligibility flow yet.
''        end note

        note right of Next #aqua
        **Assumption:**
        We are assuming that an offer is only valid for a day.
        According to DS team, if the customer does not accept a credit on that
        same day, on the next day this same credit won't be available.

        **Assumption was confirmed with DS team**
        end note



        Next->DB:  **[query 2]**\n  select * from credit_product_offers where customer_uid = customerId \n AND credit_product_type = [creditCard] \n AND enabled_ind = 'T' \n AND  credit_product_accept_dt is null
        ''**((credit_product_offer_create_dt is current date AND credit_product_accept_dt is null AND credit_product_offer_declined_dt is null) OR  \n       (credit_product_offer_create_dt < current date AND credit_product_declined_dt is **not** null) \n       **)**
        activate DB


        note right of Next #orange
        **Technical Note:**
        This query will retireve the offer that belongs to the customer and was not accepted yet.
        With this we have some possible scenarios:
        * Customer have not checked eligibility yet - which means that this is the first time since
        NBA's message was received that the customer is running throught credit
        card eligibility
        OR
        * Customer already ran through credit card
        eligibility but took no action
        OR
        * Customer was eligible to an offer in the past but declined it


        In all scenarios, we should check customer's eligibility since we might
         present the credit card offer screen again
        end note

        DB-->Next:response
        deactivate DB

        alt no offer found
          Next-->UI: HttpStauts 422 (unprocessable Entity)
          note right of UI #pink
          suggested message: Customer not eligible

          This might happen because either the customer's cpf was not sent by
          NBA message( he/she was not included on credit list-mala de credito)
          OR customer already accepted the credit card offer.
          end note
        end alt

                  Next->DB: **[query 3]** \n Select * from proposal p\n inner join proposal_products pp \n on pp.PROPOSAL_UID = p.PROPOSAL_UID\n where p.OFFERS_MAINTAINED_IND = 'Y'\n and customer_uid = customerId
                  activate DB
                  note right of Next #orange
                  **Technical Note:**
                  We retrieve current active proposal and all products linked to it.
                  On the next step, we will check if the customer has any credit products.

                  end note
                  DB-->Next:response with active proposal and its products
                  deactivate

                  note right of Next #coral
                    **Clarification:**
                    If a customer had credit products in the past, then cancelled all of them, and now he/she ran though
                    credit anlysis and became eligible to a credit card offer, should we present the screen?
                    **Answer**: Yes, the customer should receive a new credit card offer.
                    end note


                    ''  else for Active proposal (OFFERS_MAINTAINED_IND=Y), ACTIVATION_DT != current date

                          alt on active proposal: decision_code = 1 OR approved_credit > 0 OR (pp.productType = 2 and pp.productCode in (6382,6381))

                          note right of Next
                          This PB will **not** handle customers that already have credit card products, neither customer who was
                          approved on credit analysis but chose not to have a credit card.
                          In this case, customer is considered NOT eligible.
                          end note

                          Next->DB: **[query 4]** \n update credit_product_offers set credit_product_create_dt = current date,  enable_ind = 'F' \n where customer_uid = customerId  \n and credit_product_type = [creditCard]  \n and offer_uid = offerId (retrieved a couple of steps ago)
                          activate DB
                          DB-->Next:Response
                          deactivate DB


                           Next --> UI: HttpStauts 200, nothing should be presented by the app layer
                           note left of Next
                           OfferId = credit_product_offers.offer_uid;
                           **isEligibleToNewCreditCardOffer = False** (app should present credit card offer screen);
                           approvedAmount = proposal.approved_amt;
                           [add change plan response fields as example on plum note as null/zero(for amounts)/empty(for lists)]

                           Suggested message: Customer already has a credit card or customer was already approved on credit analysis.
                           end note


                           end alt
                          'else for active proposal: Customer doesn't have a credit card AND customer has approved_credit = 0 AND credit_decision_code = 2


                       alt Customer declined a credit card offer in less than or equal to [DAYS_TO_PRESENT_CREDIT_CARD_OFFER] days ago
                         note right of Next
                         The amount of days that coreNext should wait until present a new credit card offer to the customer
                         (x days) is defined on parameter '""DAYS_TO_PRESENT_CREDIT_CARD_OFFER_AFTER_DECLINED""'
                         So far, default is 30 days
                         end note

''                         Next->DB: update credit_product_offers set enable_ind = 'F' \n where customer_uid = customerId  \n and credit_product_type = [creditCard]  \n and offer_uid = offerId (retrieved a couple of steps ago)
''                         activate DB
''                         DB-->Next:Response
''                         deactivate DB

                          Next --> UI: HttpStauts 200, nothing should be presented by the app layer
                          note left of Next
                          OfferId = credit_product_offers.offer_uid;
                          **isEligibleToNewCreditCardOffer = False** (app should present credit card offer screen);
                          approvedAmount = proposal.approved_amt;
                          [add change plan response fields as example on plum note as null/zero(for amounts)/empty(for lists)]

                          Suggested message: Customer has recently declined an offer
                          end note

                          note right of Next
                          In this case, when customer the offer is still "valid", and the customer
                          will run through this use case again in the future (after 30 days).
                          end note

                          end alt
                                      ''       else  Last credit card offer declined is older than [DAYS_TO_PRESENT_CREDIT_CARD_OFFER] days

                                                  Next->CALE: GET /calendario/data
                                                  activate CALE
                                                  CALE->Next:response if current date is business day
                                                  deactivate CALE

                                                  note right of Next #white
                                                  **ref:**
                                                  Use existing methodology as in POST /plan to check if current date is a business date.
                                                  end note

                                                    alt current date is not business day OR call failed

                                                       Next-->Next: log error
                                                       Next-->UI: HttpSatus 422. Nothing should be presented by the app

                                                       note left of Next #coral
                                                       **Clarification:**
                                                       Do we need a custom message in this scenario?
                                                       Since in this case the screen shouldn't be presented
                                                       Suggested message: It is not possible to change plan outside business days
                                                       end note

                                                       note right of Next
                                                       In this case, when customer logins into the app again,
                                                        he/she will run through this use case again.

                                                        At this point, offer entry will remain as it is: like coreNext had just
                                                        received an NBA message and customer haven't checked eligibility yet.

                                                      This error doesn't mean that the customer is not eligible,
                                                        but that we can't run change plan now.

                                                       end note


                                                       end alt

                                              ''    else current date is business day
                                                        Next->CALE: GET /calendario/datahora
                                                        activate CALE
                                                        CALE-->Next: response if current time is within business hours
                                                        deactivate CALE

                                                        note right of Next #white
                                                        **ref:**
                                                        Use existing methodology as in POST /plan to check if current time is within business hours.
                                                        end note

                                                        alt current time is out of business hours OR call failed

                                                           Next-->Next: log error
                                                           Next-->UI: HttpSatus 422. Nothing should be presented by the app

                                                           note left of Next #coral
                                                           **Clarification:**
                                                           Do we need a custom message in this scenario?
                                                           Since in this case the screen shouldn't be presented

                                                            Suggested message: It is not possible to change plans outside business hours
                                                           end note

                                                           note right of Next
                                                           In this case, when customer logins into the app again,
                                                           he/she will run through this use case again.

                                                           At this point, offer entry will remain as it is: like coreNext had just
                                                           received an NBA message and customer haven't checked eligibility yet.

                                                          This error doesn't mean that the customer is not eligible,
                                                            but that we can't run change plan now.

                                                           end note

                                                           end alt

                                                           '' Since we'll always ru changePlan, should we save who was not approved on credit analysis?


                                                       note right of Next #aqua
                                                       **ASSUMPTION**
                                                       In change Plan flow, if a customer starts a new plan, don't finish it (sign T&C) and later on that same day,
                                                       this same customer goes to change plan again, Next will run whole ""GET /changePlans"" again, but will
                                                       leverage on already existing proposal (instead of creating a new one).

                                                       In order to guarantee same behaviours and avoid changing current change plan flow, if a customer get eligible
                                                       to an offer, takes no action (closes de app for example) and later on that same day, this same customer goes
                                                       into credit card offer flow again, we will call ""GET /changePlan"" and present the offer (when eligible).

                                                       We want to confirm that presenting the screen again is the expected behaviour.
                                                       end note



                                                        'else current time within business hours
                                                    group #CCDDEE apply same methodology as in GET /changePlans

                                                    Next->CP: call GET /changePlans service (UC2B) sending offer ID found or created on previous steps
                                                    activate CP

                                                    note right of Next
                                                    **Note:**
                                                    offerid added as optional so in changeplan we will run defensive checks to maintain registers consistent
                                                    end note

                                                    CP-->Next:response
                                                    deactivate CP
                                                      end group


                                                      Next->Next: check if getAvailableChangePlans() response returned plan codes 98 or 99 \nAND International credit card as possible products.

                                                            alt plan "Custom" (plan code 98 or 99) + International credit card is not a possible plan to change to

                                                                 note right of Next
                                                                 UC2B call will return all plans and products to which the customer could change to.
                                                                 PB-361 will only offer "international credit card" product.
                                                                 If UC2B doesn't return plan code 98 or 99 and  "International credit card" products  in the list as "possible plans/products to change to"
                                                                 it means that, for some reason, this plan/product is not available for the given customer, and we should not proceed with offer flow.
                                                                 (same active plan plus international credit card.)
                                                                 In this case, we consider the customer as NOT eligible to this offer
                                                                 end note


                                                                 Next->DB: **[query 5]** \n  update credit_product_offers set credit_product_create_dt = current date,  enable_ind = 'F' \n where customer_uid = customerId  \n and credit_product_type = [creditCard]  \n and offer_uid = offerId (retrieved a couple of steps ago)
                                                                 activate DB
                                                                 DB-->Next:Response
                                                                 deactivate DB


                                                                 note right of Next
                                                                  Since other plans (1,2,3,4,5,6,7,8) are "fixed" plans, where the customer can't choose what credit products he/she
                                                                  wants to acquire and each plan already has a credit card linked to it, This PB will only handle plans with code 98 and 99 (custom plan).

                                                                 * Plan Codes 5,6,7,8 and 98 were created on PB-525, and they are used as equivalent of plans 1,2,3,4 ans 99 (in this order)
                                                                to control overdraft and loan acquisition by next customers that have just onboarded.
                                                                Plan 98 and 99 are both "custom plan"

                                                                 end note

                                                                 Next-->Next: log error
                                                                  Next-->UI: HttpStatus 422 (Unprocessable Entity)

                                                                  note left of Next #coral
                                                                  **Clarification:**
                                                                  Do we need a custom message in this scenario?
                                                                  Since in this case the screen shouldn't be presented
                                                                  Suggested Message: customer is not elibile to offered plan/product
                                                                  end note


                                                            end alt

                                                            Next->DB: **[query 6]** \n select * from proposal_persistant_data where customer_uid = customerID and last_assessment_date = current date
                                                            activate DB
                                                            DB-->Next:response
                                                            deactivate DB


                                                              alt last_assessment_result creditDecisionCode = 2 OR (grantedLimit is null OR grantedLimit< = 0).\nIt means that the customer was not approved on credit assessment

                                                                  note right of Next
                                                                  If customer was not approved on credit analysis, it means that
                                                                  this customer is NOT eligible to this offer.
                                                                  end note

                                                                    Next->DB: **[query 7]** \n update credit_product_offers set \n       credit_product_create_dt = current date, \n       approved_credit_amt = last_assessment_result.grantedLimit, \n       credit_decision_code = last_assessment_result.creditDecisionCode, \n       proposal_uid = pendingProposal.proposal_uid (created/updated on getAvailableChangePlans service), \n	**enable_ind = 'F'** \n where customer_uid = customerID \n   and credit_product_offer_create_dt = current date \n   and enable_ind = 'T' \n   and offer_uid = [id fetched from previous select]
                                                                    activate DB
                                                                    DB-->Next
                                                                    deactivate DB


                                                                Next-->UI: HttpStatus 200, App should not present offer screen

                                                                note left of Next #coral
                                                                **Clarification:**
                                                                OfferId = credit_product_offers.offer_uid;
                                                                **isEligibleToNewCreditCardOffer = False** (app should NOT present credit card offer screen);
                                                                approvedAmount = credit_product.approved_amt;
                                                                [add change plan response fields as example on plum note as null/zero(for amounts)/empty(for lists)]
                                                                end note


                                                              else  last_assessment_result creditDecisionCode = 1 AND (grantedLimit is NOT null AND  grantedLimit > 0 ).It means that the customer was approved on credit assessment

                                                                  Next->DB: **[query 8]** \n update credit_product_offers set \n        credit_product_create_dt = current date, \n      approved_credit_amt = last_assessment_result.grantedLimit,\n       credit_decision_code = last_assessment_result.creditDecisionCode,\n       proposal_uid = pendingProposal.proposal_uid (created/updated on getAvailableChangePlans service)\n where customer_uid = customerID\n   and credit_product_offer_create_dt = current date\n   and enable_ind = 'T'\n   and offer_uid = [id fetched from previous select]
                                                                  activate DB
                                                                  DB-->Next
                                                                  deactivate DB

                                                                  note right of Next
                                                                  We will update the proposal id even if the offer already had an proposal_id linked to it.
                                                                  Since current change plan flow leverange on already existing pending proposals, if the customer
                                                                  starts a change plan (on change plan menu), doesn't finish it, and then receives a credit card offer, we will be sure
                                                                  to always link the last proposal created/updated during changePlan flow.
                                                                  end note

                                                                  note right of Next #orange
                                                                  **Technical Note:**
                                                                  At this point, Next should remove from available plans list all plans and products that will not be ofered by PB-361.
                                                                  This means that we only have **one plan** option (same plan as in active proposal, expected to be plan 99) and
                                                                  this plan should one have ONE product, which is **international credit card**
                                                                  end note

                                                                  Next->Next: Remove from plan list all plans that are not the same as in current active plan
                                                                  Next->Next: Remove from product list all card products that are not "international credit card"
                                                                  Next->Next: Remove from credit products lits overdraft and LOAN (LIME and LIMG)
                                                                  '' Since we'll always ru changePlan, should we save who was not approved on credit analysis?

                                                                 Next-->UI: HttpStatus 200

                                                                 note left of Next
                                                                 Response suggestion when app **should** present the screen (check purple note for reference):

                                                                 OfferId = credit_product_offers.offer_uid;
                                                                 isEligibleToNewCreditCardOffer = True (app should present credit card offer screen);
                                                                 approvedAmount = credit_product.approved_amt;
                                                                 [add change plan response fields as example on plum note]
                                                                 end note
                                                             end alt
''                                                        end alt  'end alt for business hours'

''                                                  end alt 'end alt for business day'

''                                         end alt 'end alt for "check when last credit card offer was declined"'

''                                     end alt 'end alt for "customer has changed from devit card to credit card in the last 90 days"'

''                              end alt 'end alt for "check if customer already has credit products on active proposal"'

''                      end alt 'end alt for "customer already changed plan on that same day

''               end alt  'end alt for onboarding status'

        'end alt ' end alt for "check if customer already has a credit card offer in progress"'

'end alt 'end alt for "check if one of the offer screens is enabled"' 'else removed as suggestion of Matt3'

''  note right of Next
''  **Note:**''
   'If the customer is eligible to the new offer creditCard, we don't need to go thought the card activation flow, since the credit card
   'request is not an online process, so it unlikely that the customer will be able to activate his credit card on the same day it was offered;
  'end note
''-----------------------------------------------------------------------------------------------------------------------------------------------------------'
'old flow. Awaiting for Bradesco desicion'
'also commented cache solution since it's under discussion



''          Next -> Next: Save data on cache (expirecy: every day, at midnight)
''
''          note right of Next
''          Data to be cached:
''          customer id;
''          approved amount = null;
''          isEligibleToNewCreditCardOffer = False;
''          isEligibleToCardActivation = False;
''          CreditCardLastNumbers = null;
''          creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
''          creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
''          NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
''          end note





''activation done

''      else CREDIT_CARD_ACTIVATION_SCREEN_ENABLED = true


'''      Next -> Next: Check if there's cached data for credit card offer/Activation
'''
'''      note right of Next #orange
'' ''       **Technical Note**
''  ''      If there's cached data, use it instead of fetching it from database.
''    ''  end note

''''        alt There is cached data for credit card offer/Activation
'''
'''                Next --> UI: HttpStauts 2200; Return cached data

''''        else There is no cached data for credit card offer/Activation

''          Next -> DB: select * from credit_card_offer where customer_uid = customerId and CREDIT_CARD_OFFER_ACCEPT_DATE is not null and CreditCardLastNumbers is not null and CREDIT_CARD_ACTIVATION_ACCEPT_DATE is null and ENABLE_IND = true
''          activate DB
''
''          DB --> Next: Response
''          deactivate DB
''
''                  alt Query returned no rows (Customer is not eligible to activate acredit card)
''
'''                  Next -> Next: save data on cache (expiracy: every day at midnight)

'''                  note right of Next
'''                  Data to be cached:
'''                  customer id;
'''                  approved amount = null;
'''                  isEligibleToNewCreditCardOffer = False;
'''                  isEligibleToCardActivation = False;
'''                  CreditCardLastNumbers = null;
'''                  creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
'''                  creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
'''                  NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
'''                  end note

''                  Next -->UI: HttpSatus 200. Nothing should be presented by the app

''                    note LEFT of Next
''                    Response suggestion:
''
''                    customerId = customerId;
''                    isEligibleToNewCreditCardOffer = False (app won't present credit card offer screen);
''                    approvedAmount = 0;
''                    creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
''                    isEligibleToCardActivation = False (app won't present card activation screen);
''                    CreditCardLastNumbers = null;
''                    creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
''                    NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
''                   end note



''                    note right of Next #aqua
''                    **Assumption:**
''                    If no entry was found, it means either that no credit card was accepted from the offer screen or that there's no credit card to be activated (the credit card might not be available yet)
''                    This PB will only present activation screen to credit cards that were accepted thought the offer screen.
''                    Credit cards requested from Change Plan flow won't be considered here.
''                    end note

''                  else Query returned 1 row (Customer is eligible to activate acredit card)

''                  note right of Next #coral
''                  **Clarification:**
''                  We still have no answer about having a param to present the activation screen after customer declined it.
''                  There will be such validation?
''                  end note

''                            alt Customer declined a credit card activation in less than or equal to [DAYS_TO_PRESENT_CREDIT_CARD_ACTIVATION_AFTER_DECLINED] days

''''                                Next -> Next: save data on cache (expiracy: every day at midnight)
''''
''''                                note right of Next
''''                                Data to be cached:
''''                                OfferId;
''''                                approved amount = null;
''''                                isEligibleToNewCreditCardOffer = False;
''''                                isEligibleToCardActivation = False;
''''                                CreditCardLastNumbers = null;
''''                                creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
''''                                creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
''''                                NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
''''                                end note

''                              Next -->UI: HttpSatus 200. Nothing should be presented by the app

''                            else Customer declined a credit card activation more than [DAYS_TO_PRESENT_CREDIT_CARD_ACTIVATION_AFTER_DECLINED] days ago, or has never declined.

''''                                Next -> Next: save data on cache (expiracy: every day at midnight)

''''                                note right of Next
''''                                Data to be cached:
''''                                OfferId;
''''                                approved amount = null;
''''                                isEligibleToNewCreditCardOffer = False;
''''                                isEligibleToCardActivation = True;
''''                                CreditCardLastNumbers = credit_product.CreditCardLastNumbers;
''''                                creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
''''                                creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
''''                                NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
''''                                end note

''                                Next-->UI: HttpStauts 200; present screen true + credit card last 4 numbers

''                                note LEFT of Next
''                                Response suggestion:
''
''                                customerId = customerId;
''                                isEligibleToNewCreditCardOffer = False (app won't present credit card offer screen);
''                                approvedAmount = 0;
''                                creditCardOfferDeclinedDt = credit_product.credit_card_offer_declined_dt;
''                                isEligibleToCardActivation = True (app should present card activation screen);
''                                CreditCardLastNumbers = credit_product.CreditCardLastNumbers;
''                                creditCardActivationDeclinedDt = credit_product.credit_card_activation_declined_dt;
''                                NewCreditCardOfferDate = credit_product.credit_card_offer_creation_dt
''                               end note

''                            end alt
''                    end alt
''        end alt
''      end alt
''    end alt




@enduml
