@startuml FEST Project Logical ERD

'skinparam Linetype ortho
skinparam Nodesep 50
skinparam Ranskep 50
'skinparam Linetype ortho
skinparam Nodesep 50
skinparam Ranskep 50

entity Employee {
  * Id : BigInt
  --
  * Name : Varchar 70
  * Surname : Varchar 70
  * EMail : Varchar 70
  * Username : Varchar 70
  * PasswordHash : Text
  * UserRoleId : BigInt <<FK>>
  * Active : Boolean
  PhoneNumber : Varchar 40
  BirthDate : Date
  BirthNumber : Varchar 70
  Description : Varchar 500
  IBAN : Varchar 34
  AddressId : BigInt <<FK>>
}

entity Event {
  * Id : BigInt
  --
  * Name : Varchar 200
  * StartDate: Date
  * EndDate: Date
  * Place: Varchar 100
  * Description : Varchar 500
  CompanyId : BigInt <<FK>>
}

' The app only needs to save artists' names, it doesn't really work with them in any way
' So there is no need to save more info or to have many to many relationship with Event
entity Artist {
  * Id : BigInt
  --
  * Name : Varchar 150
  * EventId : BigInt <<FK>>
}

' Enum
entity JobPosition {
  * Id : BigInt
  --
  * Position : Varchar 50
  * HourlyRate : Numeric
}

entity PreferredPosition {
  * Id : BigInt
  --
  * JobPositionId : BigInt <<FK>>
  * EmployeeId : BigInt <<FK>>
}

entity Company {
  * Id : BigInt
  --
  * Name : Varchar 100
  * Description : Varchar 500
  * Active : Boolean
}

entity Address {
  * Id : BigInt
  --
  * State : Varchar 70
  * Town : Varchar 70
  * Street : Varchar 70
  * DescriptiveNumber : Varchar 30
  * PostCode : Varchar 30
}

entity EmployeeEvent {
  * Id : BigInt
  --
  * EmployeeId : BigInt <<FK>>
  * EventId : BigInt <<FK>>
  * Description : Varchar 500
}

entity Attendance {
  * Id : BigInt
  --
  * EmployeeEventId : BigInt <<FK>>
  * JobPositionId : BigInt <<FK>>
  * RecordStateId : BigInt <<FK>>
  * Date : Date
  * Interval : Int
  * Place: Varchar 150
  * Description : Varchar 500
  ' imported from JobPosition:HourlyRate; we have to keep a separate record of a hourly rate at that moment. Hourly rate in JobPosition can change over time, but here, it has to stay the same
  * HourlyRate : Numeric
}

' Enum
entity RecordState {
  * Id : BigInt
  --
  ' enum of states of attendance records: In-process, Ready to Confirm, Confirmed, Paid
  * State : Varchar 50
}

' Enum
entity UserRole {
  * Id : BigInt
  --
  * RoleName : Varchar 50
}

Employee ||--o{ EmployeeEvent
Event ||--o{ EmployeeEvent
Attendance }o--|| EmployeeEvent
Attendance }o--|| JobPosition
Attendance }o--|| RecordState

Employee ||--o{ PreferredPosition
JobPosition ||--o{ PreferredPosition

Event ||--o{ Artist
Event }|---o| Company

Employee }|--o| Address

Employee }o--|| UserRole

@enduml