package com.mvrent.carrental.web;

import com.mvrent.carrental.model.MaintenanceRecord;

import java.math.BigDecimal;
import java.time.LocalDate;

public record MaintenanceDto(
        Long id,
        Long carId,
        String carName,
        String regNo,
        String type,
        String status,
        boolean open,
        LocalDate serviceDate,
        Integer odometer,
        BigDecimal cost,
        String garage,
        String notes,
        LocalDate nextServiceDate,
        Integer nextServiceOdometer,
        boolean dueSoon
) {
    public static MaintenanceDto from(MaintenanceRecord m) {
        var car = m.getCar();
        return new MaintenanceDto(
                m.getId(),
                car != null ? car.getId() : null,
                car != null ? car.getMake() + " " + car.getModel() : "—",
                car != null ? car.getRegistrationNumber() : "—",
                m.getType() != null ? m.getType().name() : null,
                m.getStatus() != null ? m.getStatus().name() : null,
                m.isOpen(),
                m.getServiceDate(),
                m.getOdometer(),
                m.getCost(),
                m.getGarage(),
                m.getNotes(),
                m.getNextServiceDate(),
                m.getNextServiceOdometer(),
                m.isDueSoon()
        );
    }
}
