@startuml
skinparam defaultFontSize 16

skinparam sequence {
   ArrowColor blue
   LifeLineBorderColor blue
   ParticipantBorderColor blue
   ParticipantBackgroundColor transparent
   ParticipantFontSize 16
   ActorFontColor blue
   ActorFontSize 15
   ActorFontName blue }
hide footbox

autonumber "7-"

group SD createTransactionForGroup

participant "service: \nCreateTransactionForGroupService" as service
participant "groupID:\nGroupID" as groupID
participant "groupRepo\n:GroupRepositoryDB" as groupRepo
participant "personID\n:PersonID" as personID
participant "group\n:Group" as group
participant "ledgerID\n:LedgerID" as ledgerID
participant "ledgerRepo\n:LedgerRepositoryDB" as ledgerRepo
participant "debitAccountID\n: AccountID" as debitAccountID
participant "creditAccountID\n: AccountID" as creditAccountID
participant "category\n:Category" as category
participant "ledger\n:Ledger" as ledger
participant "transaction\n:Transaction" as transaction

participant "CreateTransactionForGroupAssembler" as Assembler

'participant "responseDTO:\nCreateTransactionForGroupResponseDTO" as GDTO
'participant "requestDTO: \nCreateTransactionForGroupRequestDTO" as requestDTO
'participant "accountRepo\n:AccountRepositoryDB" as accountRepo
'participant "amount\n: Amount" as amount
'participant "dateTime\n: DateTime" as dateTime
'participant "type\n: Type" as type
'participant "description\n: Description" as description
'participant "categoryDesignation\n: Designation" as designation

-> service : createAccountForGroup \n (requestDTO)
activate service

note over ledger: requestDTO(personID : String, groupID : String, amount : String, dateTime : String, type : String,\n description : String, categoryDesignation : String, debitAccountID : String, creditAccountID : String)


'service -> requestDTO : groupID = getGroupID ()
service -> groupID* : (requestDTO.getGroupID ())
service -> groupRepo : group = findByID (groupID)
ref over groupRepo : findByID(groupID)

service -> personID *: (requestDTO.getPersonID ())

service -> group : validation1 = hasMember (personID)


service -> ledgerID* : (requestDTO.getLedgerID ())
service -> ledgerRepo : group = findByID (ledgerID)
ref over ledgerRepo : findByID(LedgerID)

service -> debitAccountID *: (requestDTO.getDebitAccountID ())
service -> creditAccountID *: (requestDTO.getCreditAccountID ())
service -> category *: (requestDTO.getCategoryDesignation ())

opt accountRepo.existsById (debitAccountID) && accountRepo.existsById (creditAccountID) && group.hasCategory (category)

'service -> requestDTO : amount = getAmount ()
'service -> amount *: (amount : String)
'service -> requestDTO : dateTime = getDateTime ()
'service -> dateTime *: (dateTime : String)
'service -> requestDTO : type = getType ()
'service -> type *: (type : String)
'service -> requestDTO : description = getDescription ()
'service -> description *: (description : String)
'service -> requestDTO : categoryDesignation = getCategoryDesignation ()
'service -> designation *: (categoryDesignation : String)
'service -> requestDTO : debitAccountID = getDebitAccountID ()
'service -> debitAccountID *: (debitAccountID : String)
'service -> requestDTO : creditAccountID = getCreditAccountID ()
'service -> creditAccountID *: (creditAccountID : String)

service -> ledger : addTransaction (requestDTO.getAmount (), requestDTO.dateTime,() requestDTO.type (), requestDTO.description (), category, debitAccountID, creditAccountID)
ledger -> transaction* : (amount, \n dateTime, \n type, \n description, \n categoryDesignation, \n debitAccountID, \n creditAccountID)

service -> ledgerRepo : save (ledger)
ref over ledgerRepo : save (ledger)

service -> Assembler : responseDTO = mapToDTOResponse(group.getGroupID.toStringDTO (), group.getDescription.getDescription (), requestDTO.getAmount (), requestDTO.getType (), requestDTO.getDescription ())
'activate Assembler
'Assembler -> GDTO* : (group.getGroupID.toStringDTO (), \n group.getDescription.getDescription (),\n requestDTO.getAmount (), \n requestDTO.getType (), \n requestDTO.getDescription ())

ref over Assembler : createResponseDTO


Assembler --> service : responseDTO
deactivate Assembler

<-- service : responseDTO
deactivate service

end

end
@enduml