package com.mvrent.carrental.web;

import com.mvrent.carrental.model.InspectionRecord;

import java.time.LocalDate;

public record InspectionDto(
        Long id,
        Long carId,
        String carName,
        String regNo,
        Long bookingId,
        String type,
        String condition,
        boolean hasDamage,
        LocalDate inspectionDate,
        String inspector,
        Integer odometer,
        Integer fuelLevel,
        String damageNotes,
        String photoUrl
) {
    public static InspectionDto from(InspectionRecord r) {
        var car = r.getCar();
        return new InspectionDto(
                r.getId(),
                car != null ? car.getId() : null,
                car != null ? car.getMake() + " " + car.getModel() : "—",
                car != null ? car.getRegistrationNumber() : "—",
                r.getBooking() != null ? r.getBooking().getId() : null,
                r.getType() != null ? r.getType().name() : null,
                r.getCondition() != null ? r.getCondition().name() : null,
                r.hasDamage(),
                r.getInspectionDate(),
                r.getInspector(),
                r.getOdometer(),
                r.getFuelLevel(),
                r.getDamageNotes(),
                r.getPhotoUrl()
        );
    }
}
