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

'diagram title'
title PB-361 UC6 - GET customer's cpf from NBA message

'a list of the actors and participants'
actor "NBA listener" as NBA
box "Next Platform"
participant "Core Next" as Next
database "Next Database" as DB
end box


'a brief description of the diagram'
legend top
-- \t**Abstract:**\t --
We will change an already existing listener to retrieve a customer's CPF and store it in next database when NBA's message identifies that the customer may have approved credit to use.
Important: Neither the message code or the message content is defined yet.
end legend

NBA->NBA:

opt message code is [xxxxx] (TBD)
note right of Next #orange
**Technical Note:**
A new NBA message will be created.
Use existing methodology to allow Next to handle this new message.
end note

Next->Next: fetch customer id from cpf provided by NBA message


note right of Next #coral
**Clarification:**
What should be done if NBA send a message for a customer, but the customer
doesn't go throught credit card eligibility flow, and then NBA sends another
message for that same customer a couple of days later?
What should happen on this scenario?
**Answer:** We should only considet the most recent NBA message
end note

Next->DB: update credit_product_offers set enable_ind = 'F' \n where customer_uid = customerId \n and credit_product_offer_create_dt is null \n and credit_product_type = [creditCard] \n and enable_ind = 'T'
activate DB
note right of Next
First, coreNext should deactive any old credit card offer entry for the given \n
customer that was not started yet (customer didn't ran throught eligbility endpoint).
end note
DB-->Next:response

Next->DB: insert into cerdit_product_offer customer_uid = customerId, enable_ind = 'T', credit_product_type = [credirCard];
activate DB


note right of Next
NBA messag will trigger the credit card offer flow.
When identifying that NBA's message was sent to warn the customer that he/she
might have approved_credit, coreNext will store this CPF on credit_product_offers
table.
This will be used on UC1 to limit the group of customers that will be sent throught eligiblity flow.
end note

note right of Next #aqua
**Assumption:**
Since this PC will only offer international credit card, when adding customer's
CPF on offer table, we will also add the offer type (creditCard).
In future PB's, we should review logic, in case this very same NBA message is used as a trigger for other offer types.
end note



DB-->Next:Response
deactivate DB


end opt


note right of Next
maintain already existing methodology
end note

@enduml
