package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Car;

import java.math.BigDecimal;

/** Flat JSON view of a Car for the AJAX Manage Cars screen. */
public record CarDto(
        Long id,
        String make,
        String model,
        String registrationNumber,
        Integer yearOfRegistration,
        String colour,
        String type,
        int seats,
        String transmission,
        String fuelType,
        String featureTagsCsv,
        BigDecimal hourlyRate,
        BigDecimal pricePerDay,
        BigDecimal monthlyRate,
        String ownership,
        Long vendorId,
        String vendorName,
        BigDecimal commissionPercentOverride,
        int unitsTotal,
        String status,
        String imageUrl,
        boolean available
) {
    public static CarDto from(Car c) {
        return new CarDto(
                c.getId(), c.getMake(), c.getModel(), c.getRegistrationNumber(),
                c.getYearOfRegistration(), c.getColour(),
                c.getType() != null ? c.getType().name() : null,
                c.getSeats(),
                c.getTransmission() != null ? c.getTransmission().name() : null,
                c.getFuelType() != null ? c.getFuelType().name() : null,
                String.join(", ", c.getFeatureTags()),
                c.getHourlyRate(), c.getPricePerDay(), c.getMonthlyRate(),
                c.getOwnership() != null ? c.getOwnership().name() : "OWNED",
                c.getVendor() != null ? c.getVendor().getId() : null,
                c.getVendor() != null ? c.getVendor().getName() : null,
                c.getCommissionPercentOverride(),
                c.getUnitsTotal(),
                c.getStatus() != null ? c.getStatus().name() : "ACTIVE",
                c.getImageUrl(),
                c.isAvailable()
        );
    }
}
