@startuml
title Class Diagram

class Department {
  +MEcrDepartment()
  +MEendDepartment()
  +Accept()
  +Invalidate()
  +Leave()
  +MEcrBed()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEcrRoom()
  +MEcrStay()
  +MEendBed()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
  +MEendRoom()
  +MEendStay()
  +Propose()
  +Refuse()
  +Validate()
}

class Category {
  +MEcrCategory()
  +MEendCategory()
  +Accept()
  +Invalidate()
  +Leave()
  +MEcrBed()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEcrRoom()
  +MEcrStay()
  +MEendBed()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
  +MEendRoom()
  +MEendStay()
  +Propose()
  +Refuse()
  +Validate()
}

class Room {
  +MEcrRoom()
  +MEendRoom()
  +Accept()
  +Invalidate()
  +Leave()
  +MEcrBed()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEcrStay()
  +MEendBed()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
  +MEendStay()
  +Propose()
  +Refuse()
  +Validate()
}

class Bed {
  +MEcrBed()
  +MEendBed()
  +Accept()
  +Invalidate()
  +Leave()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEcrStay()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
  +MEendStay()
  +Propose()
  +Refuse()
  +Validate()
}

class Person {
  +MEcrPerson()
  +MEendPerson()
  +Assess()
  +Accept()
  +EndUnpaid()
  +Invalidate()
  +Leave()
  +MEcrInvoice()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEcrStay()
  +MEendInvoice()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
  +MEendStay()
  +Pay()
  +Propose()
  +ReceiveFullPayment()
  +Refuse()
  +Validate()
}

class Proposal {
  +MEcrProposal()
  +Invalidate()
  +Refuse()
  +Validate()
  +Accept()
  +Propose()
}

class Stay {
  +MEcrStay()
  +MEendStay()
  +Leave()
  +MEcrInvoiceItem()
  +MEcrInvoiceLine()
  +MEendInvoiceItem()
  +MEendInvoiceLine()
}

class Invoice {
  +MEcrInvoice()
  +EndUnpaid()
  +MEendInvoice()
  +Pay()
  +ReceiveFullPayment()
  +MEcrInvoiceLine()
  +MEendInvoiceLine()
}

class InvoiceItem {
  +MEcrInvoiceItem()
  +MEendInvoiceItem()
  +MEcrInvoiceLine()
  +MEendInvoiceLine()
}

class InvoiceLine {
  +MEcrInvoiceLine()
  +MEendInvoiceLine()
}

' Structure of the home
Department "1" -- "0..*" Room : contains
Room       "1" -- "1..*" Bed  : contains
Category "1" -- "0..*" Bed : classifies

' Categories / types of stay

' Person lifecycle: proposals, stays, invoices
Person "1" -- "0..*" Proposal : requests
Person "1" -- "0..*" Stay     : has
Person "1" -- "0..*" Invoice  : billedTo

' Bed usage: proposals and stays
Bed "1" -- "0..*" Proposal : offeredOn
Bed "1" -- "0..*" Stay     : assignedTo


' Stays and billing
Stay        "1" -- "0..*" InvoiceItem : billedFor
InvoiceItem "1" -- "0..*" InvoiceLine : detailedBy
Invoice     "1" -- "1..*" InvoiceLine : aggregates

@enduml

@startuml
title BedRole (Bed)

[*] --> initial
ended --> [*]
state empty
state inUse
state assigned

initial --> empty : initialEmpty / MEcrBed
empty --> ended : emptyEnded / MEendBed
empty --> empty : emptyEmpty / Propose, Refuse, Invalidate, Accept
empty --> assigned : emptyAssigned / Validate
assigned --> inUse : assignedInUse / MEcrStay
inUse --> empty : inUseEmpty / Leave
@enduml

@startuml
title InvoiceRole (Invoice)

[*] --> initial
ended --> [*]
state open
state paid

initial --> open : initialOpen / MEcrInvoice
open --> ended : openEnded / EndUnpaid
open --> paid : openPaid / ReceiveFullPayment
paid --> paid : paidPaid / MEendInvoiceLine
paid --> ended : paidEnded / MEendInvoice
open --> open : openOpen / MEcrInvoiceLine, MEendInvoiceLine, Pay
@enduml

@startuml
title InvoiceItemLife (InvoiceItem)

[*] --> initial
ended --> [*]
state Exists
state Invoiced

initial --> Exists : initialExists / MEcrInvoiceItem
Exists --> Invoiced : ExistsInvoiced / MEcrInvoiceLine
Invoiced --> Invoiced : InvoicedInvoiced / MEendInvoiceLine
Invoiced --> ended : InvoicedEnded / MEendInvoiceItem
Exists --> ended : ExistsEnded / MEendInvoiceItem
@enduml

@startuml
title PersonRole (Person)

[*] --> initial
ended --> [*]
state exists
state onWaitingList
state Inhabitant

initial --> exists : initialExists / MEcrPerson
exists --> ended : existsEnded / MEendPerson
exists --> onWaitingList : existsOnWaitingList / Assess
onWaitingList --> ended : onWaitingListEnded / MEendPerson
onWaitingList --> onWaitingList : onWaitingListOnWaitingList / Propose, Refuse, Accept, Invalidate, Assess
onWaitingList --> Inhabitant : onWaitingListInhabitant / Validate
Inhabitant --> ended : InhabitantEnded / MEendPerson
Inhabitant --> Inhabitant : InhabitantInhabitant / MEcrInvoice, MEcrInvoiceItem, MEcrInvoiceLine, MEcrStay, MEendInvoice, MEendInvoiceItem, MEendInvoiceLine, MEendStay, EndUnpaid, Leave, Pay, ReceiveFullPayment, MEcrInvoiceLine, MEendInvoiceLine
@enduml

@startuml
title ProposalRole (Proposal)

[*] --> initial
state exists
refused --> [*]
validated --> [*]
state accepted
invalidated --> [*]

initial --> exists : initialExists / Propose
exists --> refused : existsRefused / Refuse
accepted --> invalidated : acceptedInvalidated / Invalidate
accepted --> validated : acceptedValidated / Validate
exists --> accepted : existsAccepted / Accept
@enduml

@startuml
title StayCalculated (Stay)

[*] --> initial
state ongoing
state stopped
ended --> [*]

initial --> ongoing : initialOnGoing / MEcrStay
ongoing --> suspended : OnGoingSuspended / Suspend
ongoing --> ongoing : OnGoingOnGoing / MEcrInvoiceItem, MEcrInvoiceLine, MEendInvoiceItem, MEendInvoiceLine
suspended --> ended : SuspendedEnded / MEendStay
suspended --> suspended : SuspendedSuspended / MEcrInvoiceLine, MEendInvoiceLine, MEendInvoiceItem
suspended --> ongoing : SuspendedOnGoing / BackToOriginalStay
ongoing --> ended : ongoingEnded / MEendStay
@enduml