package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Driver;

import java.util.List;

/** Documents of a driver, for the AJAX documents modal. */
public record DriverMediaDto(List<Doc> documents) {

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

    public static DriverMediaDto from(Driver d) {
        List<Doc> docs = d.getDocuments().stream().map(x -> new Doc(
                x.getId(),
                x.getDocType() != null ? x.getDocType().name() : null,
                x.getFileUrl(),
                x.getIssuedDate() != null ? x.getIssuedDate().toString() : null,
                x.getExpiryDate() != null ? x.getExpiryDate().toString() : null,
                x.isExpired() ? "EXPIRED" : (x.isExpiringSoon() ? "EXPIRING" : "OK")
        )).toList();
        return new DriverMediaDto(docs);
    }
}
