@startuml
'diagram parameters'

autonumber
'skinparam dpi 300
skinparam LegendBackgroundColor #white

'diagram title'
title PB-351 - UC-5.1 Activate or deactivate a Mimo Card

'a list of the actors and participants'

actor "System Management" as SM
box "Next"
    participant "P&O" as PO
    database "PO_DB" as PO_DB
end box

'a brief description of the diagram'
legend top
    -- \t**Abstract:**\t --
    Allows system manager to activate or deactivate a Mimo card.
    Only Active Mimo Cards are shown to the Customers.
end legend

note right of SM #plum
    **Endpoint**
    PUT /v1/mimos/cards/{cardId}/status

    **Current implementation:**
    None.

    **Required implementation:**
    Change the STATUS of a Mimo Card, activating or deactivating it.
    Inputs:
    ""MimoCardActivation""
    ""{ ""
    ""  status: Boolean (ACTIVE / INACTIVE)""
    ""} ""

    Outputs:
    * responseCode

    State changes: update a record in the MIMO_CARD table in the P&O.
end note

note right of SM
This endpoint will be used only by System Management.
end note

note right of SM #coral
    **Clarification:**
    Ativar ou desativar um card deve incrementar a versão dele?
end note

SM->PO: **HTTP**\n""PUT /v1/mimos/cards/{cardId}/status""\n""MimoCardActivation""
activate PO

    note right of PO
        Validation
    end note

    group #transparent if status is NULL
        note right of SM: Failed, record not updated

        note right of SM
            HTTP error code: 422
            Error message: Bad request
        end note
        PO-->SM: responseCode=error
    end group

    note right of PO
        Update the record at the MIMO_CARD table.
    end note

    PO -> PO_DB: **SQL**\n""UPDATE MIMO_CARD""\n""   SET STATUS = :status""\n"" WHERE MIMO_CARD_UID = :cardId"";
    activate PO_DB
        PO_DB --> PO: MIMO_CARD activated or deactivated
    deactivate PO_DB

    group #transparent if card successfully updated
        note right of SM: HTTP success code: 200
        PO-->SM: mimoCard
    end group

    group #transparent else other errors
        note right of SM: Failed, record not updated

        note right of SM
            HTTP error code: 500
            Error message: Unexpected error
        end note
        PO-->SM: responseCode=error
        deactivate PO
    end group

@enduml
