@startuml
skinparam monochrome true
skinparam packageStyle rectangle
skinparam shadowing false

title System Sequence Diagram (SSD)

autonumber

actor "Human Resources\nManager (HRM)" as HRM
participant ":RegisterCollaboratorUI" as UI
participant ":RegisterCollaboratorController" as CTRL
participant ":Repositories" as REPS
participant "repositories\n:Repositories" as REP
participant "documentTypeRep\n:DocumentTypeRep" as DTR
participant "jobRepository\n:JobRepository" as JR
participant "addressRepository\n:AddressRepository" as ADR
participant "address\n:Address" as AD
participant "collaboratorRepository\n:CollaboratorRepository" as CR
participant "collaborator\n:Collaborator" as Collaborator

activate HRM

    HRM -> UI : asks to register a new collaborator
    activate UI

    UI -> CTRL** : create

        UI --> HRM : requests collaborator data (i.e., collaborator name, birthdate, \nadmission date, taxpayer number, street name, zip code, city, \ntelephone number and email address).
    deactivate UI

    HRM -> UI : types requested data
    activate UI

    UI -> UI : keepData

    UI --> CTRL : getDocumentTypes()

    activate CTRL

                CTRL -> REPS : getInstance()
                activate REPS

                    REPS --> CTRL : repositories
                deactivate REPS

                CTRL -> REP : getDocumentTypeRepository()
                activate REP

                    REP --> CTRL : documentTypeRepository
                deactivate REP

                CTRL -> DTR : getIdTypes()
                activate DTR

                    DTR --> CTRL : idDocumentTypesList
                deactivate DTR

                CTRL --> UI : idDocumentTypesList
            deactivate CTRL

    UI --> HRM : displays the list of identification document types and asks \nto select one
        deactivate UI

        HRM -> UI : selects an ID document type
        activate UI

        UI -> UI : keepIdDocumentType

        UI --> HRM : requests identification number
            deactivate UI

            HRM -> UI : types the requested ID number
            activate UI

            UI -> UI : keepIdNumber

            UI -> CTRL : getJobsList()
                    activate CTRL

                        CTRL -> REPS : getInstance()
                        activate REPS

                            REPS --> CTRL : repositories
                        deactivate REPS

                        CTRL -> REP : getJobRepository()
                        activate REP

                            REP --> CTRL : JobRepository
                        deactivate REP

                        CTRL -> JR : getJobs()
                        activate JR

                            JR --> CTRL : jobsList
                        deactivate JR

                        CTRL --> UI : jobsList
                    deactivate CTRL


        UI --> HRM : shows the company's list of jobs and asks to select the job \nthat the employee will perform
    deactivate UI

    HRM -> UI : selects a job
    activate UI

    UI -> UI : keepJobName

        UI --> HRM : asks if it is necessary to register any other relevant information
            deactivate UI

            HRM -> UI : provides the information if relevant or simply proceed
            activate UI
            UI -> UI : keepOtherRelevantInformation

    UI --> HRM : shows all data about the collaborator and requests confirmation
        deactivate UI

        HRM -> UI : confirms data
        activate UI

    UI -> CTRL : registerCollaborator(collaboratorName, birthdate, admissionDate, \ntaxpayerNumber, streetName, zipCode, city, phoneNumber, \nemailAddress, idDocumentType, idNumber, jobName)
            activate CTRL

                CTRL -> REPS : getInstance()
                activate REPS

                    REPS --> CTRL : repositories
                deactivate REPS


                CTRL -> REP : getAddressRepository()
                activate REP

                     REP --> CTRL : addressRepository
                deactivate REP




                CTRL -> ADR : registerAddress(streetName, zipCode, city)
                        activate ADR

                        ADR -> AD** : create

                ADR --> CTRL : address
                        deactivate ADR

                CTRL -> CR : registerCollaborator(collaboratorName, birthdate, admissionDate, taxpayerNumber, address, \nphoneNumber, emailAddress, idDocumentType, idNumber, jobName, otherRelevantInformation)
                     activate CR

                    CR -> Collaborator** : create a collaborator with provided attributes

                    CR -> CR : addCollaborator(collaborator)
                    activate CR

                        CR -> CR : validateCollaborator(collaborator)

                        activate CR

                            CR --> CR : true/false
                        deactivate CR

                        CR --> CR : true/false
                    deactivate CR

                    CR --> CTRL : true/false
                deactivate CR

                CTRL --> UI : true/false
            deactivate CTRL

        UI --> HRM : displays operation success
    deactivate UI

@enduml