package com.mvrent.carrental.web;

import com.mvrent.carrental.model.VehicleLocation;

import java.time.LocalDateTime;

public record VehicleLocationDto(
        Long carId,
        String carName,
        String regNo,
        String status,
        double latitude,
        double longitude,
        Double speedKph,
        Double heading,
        Integer odometer,
        Boolean ignitionOn,
        boolean live,
        LocalDateTime updatedAt
) {
    public static VehicleLocationDto from(VehicleLocation v) {
        var car = v.getCar();
        return new VehicleLocationDto(
                car != null ? car.getId() : null,
                car != null ? car.getMake() + " " + car.getModel() : "—",
                car != null ? car.getRegistrationNumber() : "—",
                car != null && car.getStatus() != null ? car.getStatus().name() : null,
                v.getLatitude(),
                v.getLongitude(),
                v.getSpeedKph(),
                v.getHeading(),
                v.getOdometer(),
                v.getIgnitionOn(),
                v.isLive(),
                v.getUpdatedAt()
        );
    }
}
