package com.mvrent.carrental.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import lombok.*;

import java.time.LocalDate;

/** A document for a driver (licence, ID proof, …) with expiry tracking. */
@Entity
@Table(name = "driver_documents")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DriverDocument {

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

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "driver_id")
    private Driver driver;

    @Enumerated(EnumType.STRING)
    @NotNull
    private DriverDocumentType docType;

    private String fileUrl;

    private LocalDate issuedDate;

    private LocalDate expiryDate;

    @Transient
    public boolean isExpired() {
        return expiryDate != null && expiryDate.isBefore(LocalDate.now());
    }

    @Transient
    public boolean isExpiringSoon() {
        return expiryDate != null
                && !expiryDate.isBefore(LocalDate.now())
                && expiryDate.isBefore(LocalDate.now().plusDays(30));
    }
}
