package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Car;

import java.util.List;

/** Documents + photos of a car, for the AJAX media modal. */
public record CarMediaDto(List<Doc> documents, List<Photo> photos) {

    public record Doc(Long id, String docType, String fileUrl, String issuedDate, String expiryDate, String state) {}
    public record Photo(Long id, String url) {}

    public static CarMediaDto from(Car c) {
        List<Doc> docs = c.getDocuments().stream().map(d -> new Doc(
                d.getId(),
                d.getDocType() != null ? d.getDocType().name() : null,
                d.getFileUrl(),
                d.getIssuedDate() != null ? d.getIssuedDate().toString() : null,
                d.getExpiryDate() != null ? d.getExpiryDate().toString() : null,
                d.isExpired() ? "EXPIRED" : (d.isExpiringSoon() ? "EXPIRING" : "OK")
        )).toList();
        List<Photo> photos = c.getPhotos().stream().map(p -> new Photo(p.getId(), p.getUrl())).toList();
        return new CarMediaDto(docs, photos);
    }
}
