package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Driver;

import java.math.BigDecimal;

/** Flat JSON view of a Driver for the AJAX Manage Drivers screen. */
public record DriverDto(
        Long id,
        String name,
        String phone,
        String licenceNumber,
        String licenceExpiry,
        boolean licenceExpired,
        int yearsExperience,
        Long categoryId,
        String categoryName,
        String employmentType,
        Long vendorId,
        String vendorName,
        BigDecimal hourlyCharge,
        BigDecimal dailyCharge,
        BigDecimal monthlyCharge,
        String status,
        String photoUrl
) {
    public static DriverDto from(Driver d) {
        return new DriverDto(
                d.getId(), d.getName(), d.getPhone(), d.getLicenceNumber(),
                d.getLicenceExpiry() != null ? d.getLicenceExpiry().toString() : null,
                d.isLicenceExpired(),
                d.getYearsExperience(),
                d.getCategory() != null ? d.getCategory().getId() : null,
                d.getCategory() != null ? d.getCategory().getName() : null,
                d.getEmploymentType() != null ? d.getEmploymentType().name() : "EMPLOYED",
                d.getVendor() != null ? d.getVendor().getId() : null,
                d.getVendor() != null ? d.getVendor().getName() : null,
                d.getHourlyCharge(), d.getDailyCharge(), d.getMonthlyCharge(),
                d.getStatus() != null ? d.getStatus().name() : "AVAILABLE",
                d.getPhotoUrl()
        );
    }
}
