package com.mvrent.carrental.web;

import com.mvrent.carrental.model.Review;

import java.time.LocalDateTime;

public record ReviewDto(
        Long id,
        Long carId,
        String carName,
        String customerName,
        Long bookingId,
        int rating,
        String comment,
        boolean approved,
        LocalDateTime createdAt
) {
    public static ReviewDto from(Review r) {
        var car = r.getCar();
        var u = r.getUser();
        return new ReviewDto(
                r.getId(),
                car != null ? car.getId() : null,
                car != null ? car.getMake() + " " + car.getModel() : "—",
                u != null ? (u.getFullName() != null ? u.getFullName() : u.getUsername()) : "—",
                r.getBooking() != null ? r.getBooking().getId() : null,
                r.getRating(),
                r.getComment(),
                r.isApproved(),
                r.getCreatedAt()
        );
    }
}
