package com.mvrent.carrental.model;

import jakarta.persistence.*;
import lombok.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/** A customer invoice generated for a booking. */
@Entity
@Table(name = "invoices")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Invoice {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "booking_id", unique = true)
    private Booking booking;

    @Column(unique = true, nullable = false)
    private String invoiceNumber;

    @Column(nullable = false, updatable = false)
    private LocalDateTime issuedAt;

    private BigDecimal subtotal;
    private BigDecimal taxAmount;
    private BigDecimal total;

    @PrePersist
    void onCreate() {
        if (issuedAt == null) issuedAt = LocalDateTime.now();
    }
}
