# UML Class Diagram

```mermaid
classDiagram
    class App {
        +main(String[] args)
    }

    class ConsoleUi {
        -WorkshopService service
        -Scanner scanner
        +ConsoleUi(WorkshopService service)
        +start()
        -printMenu()
        -addPerson()
        -listPersons()
        -addVehicle()
        -listVehiclesOfPerson()
        -createWorkOrder()
        -listWorkOrders()
        -importPersons()
        -exportPersons()
    }

    class WorkshopService {
        -PersonDao personDao
        -VehicleDao vehicleDao
        -ServiceItemDao serviceItemDao
        -WorkOrderDao workOrderDao
        +WorkshopService()
        +createPerson(String name, String phone) Person
        +listPersons() List~Person~
        +createVehicle(int personId, String brand, String model, String plate) Vehicle
        +listVehicles(int personId) List~Vehicle~
        +listServiceItems() List~ServiceItem~
        +createWorkOrder(int vehicleId, String note, Map~Integer, Integer~ items) int
        +listWorkOrders() List~WorkOrderDetails~
        +findPerson(int id) Person
        +findVehicle(int id) Vehicle
    }

    class Database {
        +getConnection() Connection$
    }

    class Person {
        -int id
        -String name
        -String phone
        +Person(int id, String name, String phone)
        +getId() int
        +getName() String
        +getPhone() String
        +toString() String
    }

    class Vehicle {
        -int id
        -int personId
        -String brand
        -String model
        -String plate
        +Vehicle(int id, int personId, String brand, String model, String plate)
        +getId() int
        +getPersonId() int
        +getBrand() String
        +getModel() String
        +getPlate() String
        +toString() String
    }

    class ServiceItem {
        -int id
        -String title
        -BigDecimal price
        +ServiceItem(int id, String title, BigDecimal price)
        +getId() int
        +getTitle() String
        +getPrice() BigDecimal
        +toString() String
    }

    class WorkOrder {
        -int id
        -int vehicleId
        -String note
        -LocalDateTime createdAt
        +WorkOrder(int id, int vehicleId, String note, LocalDateTime createdAt)
        +getId() int
        +getVehicleId() int
        +getNote() String
        +getCreatedAt() LocalDateTime
    }

    class WorkOrderItem {
        -int id
        -int workOrderId
        -ServiceItem serviceItem
        -int quantity
        +WorkOrderItem(int id, int workOrderId, ServiceItem serviceItem, int quantity)
        +getId() int
        +getWorkOrderId() int
        +getServiceItem() ServiceItem
        +getQuantity() int
        +getTotalPrice() BigDecimal
    }

    class WorkOrderDetails {
        -int orderId
        -String personName
        -String vehicleText
        -LocalDateTime createdAt
        -String note
        -List~WorkOrderItem~ items
        -BigDecimal total
        +WorkOrderDetails(int orderId, String personName, String vehicleText, LocalDateTime createdAt, String note, List~WorkOrderItem~ items, BigDecimal total)
        +getOrderId() int
        +getPersonName() String
        +getVehicleText() String
        +getCreatedAt() LocalDateTime
        +getNote() String
        +getItems() List~WorkOrderItem~
        +getTotal() BigDecimal
    }

    class PersonDao {
        +create(String name, String phone) Person
        +findAll() List~Person~
        +findById(int id) Person
    }

    class VehicleDao {
        +create(int personId, String brand, String model, String plate) Vehicle
        +findByPerson(int personId) List~Vehicle~
        +findById(int id) Vehicle
    }

    class ServiceItemDao {
        +findAll() List~ServiceItem~
        +seedDefaultItems()
    }

    class WorkOrderDao {
        +createWorkOrder(int vehicleId, String note, Map~Integer, Integer~ items) int
        +fetchAllDetails() List~WorkOrderDetails~
    }

    class SchemaCreator {
        +ensureSchema()
    }

    namespace importers {
        class IImporter~T~ {
            <<interface>>
            +importData(String path) List~T~
        }

        class CsvPersonImporter {
            +importData(String path) List~Person~
        }
    }

    namespace exporters {
        class IExporter~T~ {
            <<interface>>
            +exportData(List~T~ data, String path)
        }

        class CsvPersonExporter {
            +exportData(List~Person~ data, String path)
        }
    }

    namespace loggers {
        class ILogger {
            <<interface>>
            +Log()
        }
    }

    App ..> ConsoleUi : creates
    App ..> WorkshopService : creates
    ConsoleUi --> WorkshopService : uses
    ConsoleUi ..> CsvPersonImporter : creates
    ConsoleUi ..> CsvPersonExporter : creates

    WorkshopService --> PersonDao : uses
    WorkshopService --> VehicleDao : uses
    WorkshopService --> ServiceItemDao : uses
    WorkshopService --> WorkOrderDao : uses
    WorkshopService ..> SchemaCreator : uses

    PersonDao ..> Person : uses
    VehicleDao ..> Vehicle : uses
    ServiceItemDao ..> ServiceItem : uses
    WorkOrderDao ..> WorkOrder : uses
    WorkOrderDao ..> WorkOrderDetails : creates
    WorkOrderDao ..> WorkOrderItem : creates

    WorkOrderDetails *-- WorkOrderItem : contains
    WorkOrderItem --> ServiceItem : has

    CsvPersonImporter ..|> IImporter : implements
    CsvPersonExporter ..|> IExporter : implements
    
    PersonDao ..> Database : uses
    VehicleDao ..> Database : uses
    ServiceItemDao ..> Database : uses
    WorkOrderDao ..> Database : uses
```
