package com.mvrent.carrental.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDate;
import java.time.LocalDateTime;

/** A pre/post-trip or periodic condition & damage inspection of a car. */
@Entity
@Table(name = "inspection_records")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class InspectionRecord {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "car_id")
    private Car car;

    /** Optional link to the trip this inspection belongs to. */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "booking_id")
    private Booking booking;

    @Enumerated(EnumType.STRING)
    @NotNull
    private InspectionType type;

    @Enumerated(EnumType.STRING)
    @NotNull
    @Builder.Default
    private InspectionCondition condition = InspectionCondition.GOOD;

    private LocalDate inspectionDate;

    private String inspector;

    private Integer odometer;

    /** Fuel level as a percentage 0–100. */
    private Integer fuelLevel;

    @Column(length = 1000)
    private String damageNotes;

    /** Path/URL to an uploaded photo of the damage / condition. */
    private String photoUrl;

    @CreationTimestamp
    private LocalDateTime createdAt;

    @Transient
    public boolean hasDamage() {
        return condition != null && condition != InspectionCondition.GOOD;
    }
}
