package marketing.heyday.hartmann.fotodocumentation.rest.vo;

import java.util.Date;

import io.swagger.v3.oas.annotations.media.Schema;
import marketing.heyday.hartmann.fotodocumentation.core.model.Customer;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;

/**
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 19 Jan 2026
 */

@Schema(name = "CustomerList")
public record CustomerListValue(Long id, String name, String customerNumber, Date lastUpdateDate) {

	public static CustomerListValue builder(Customer customer) {
		if (customer == null) {
			return null;
		}
		Date date = customer.getPictures().stream().map(Picture::getPictureDate).sorted((p1, p2) -> p2.compareTo(p1)).findFirst().orElse(null);
		return new CustomerListValue(customer.getCustomerId(), customer.getName(), customer.getCustomerNumber(), date);
	}
}
