@startuml
skinparam monochrome true
skinparam packageStyle rectangle
skinparam shadowing false

autonumber


actor "System Administrator" as Admin
participant ":RegisterEmployeeUI" as UI
participant ":RegisterEmployeeController" as CTRL
participant ":Repositories" as RepositorySingleton
participant "repositories\n:Repositories" as PLAT
participant ":ApplicationSession" as _APP
participant "appSession\n:ApplicationSession" as APP
participant "currentSession\n:UserSession" as SESSAO
participant "organizationRepository:\nOrganizationRepository" as OrganizationRepository
participant "organization\n:Organization" as ORG
participant "employee\n:Employee" as EMPLOYEE

activate Admin

Admin --> UI: asks to register a new employee
activate UI

UI --> CTRL**: register

  UI --> Admin : Requests data
    deactivate UI
    Admin -> UI : Inserts requested data (name, citizen's card number,\ntax number, address, e-mail address, contact telephone\n number, role in the company, agency assigned)
    activate UI

    UI --> CTRL : registerEmployee(name, citizen's card number,\ntax number, address, e-mail address, contact telephone\n number, role in the company, agency assigned)
    activate CTRL


                CTRL --> CTRL : getEmployeeFromSession()
                activate CTRL

                    CTRL --> _APP: getInstance()
                    activate _APP
                        _APP --> CTRL: appSession
                    deactivate _APP


                    CTRL --> APP: getCurrentSession()
                    activate APP

                        APP --> CTRL: currentSession
                    deactivate APP

                    CTRL --> SESSAO: email = getUserEmail()
                    activate SESSAO

                        SESSAO --> CTRL: email
                    deactivate SESSAO


                    CTRL --> PLAT: getOrganizationRepository(email)
                    activate PLAT

                    PLAT --> CTRL : organizationRepository
                    deactivate PLAT

                    CTRL -> OrganizationRepository: getOrganizationByEmployeeEmail(email)
                                    activate OrganizationRepository

                                        loop [for each organization
                                            OrganizationRepository -> ORG : anyEmployeeHasEmail(email)
                                            activate ORG

                                                 ORG --> OrganizationRepository : true/false
                                            deactivate ORG
                                        end
                                        OrganizationRepository --> CTRL : organization
                                    deactivate OrganizationRepository

                    CTRL -> ORG: getEmployeeByEmail(email)
                        activate ORG

                        ORG --> CTRL : System Administrator
                        deactivate ORG

                    CTRL --> CTRL : System Administrator
                    deactivate CTRL



    CTRL --> ORG : registerEmployee(name, citizen's card number,\ntax number, address, e-mail address, contact telephone\n number, role in the company, agency assigned)

activate ORG

ORG --> EMPLOYEE**: registerEmployee(name, citizen's card number,\ntax number, address, e-mail address, contact telephone\n number, role in the company, agency assigned)
ORG --> ORG : addEmployee(employee)
activate ORG

    ORG --> ORG : validatesEmployee(employee)
    deactivate ORG

ORG --> CTRL : employee
deactivate ORG

CTRL-->UI : employee
deactivate CTRL

    UI --> EMPLOYEE: sends password to the employee e-mail

     UI --> Admin : Shows operation success
deactivate UI






@enduml
