package com.example.backend.ordersbooks.model;

import java.util.Objects;
import java.util.Optional;

import jakarta.persistence.Embeddable;

@Embeddable
public class OrderBookId {
    private Long orderId;
    private Long bookId;

    public OrderBookId() {
    }

    public OrderBookId(Long orderId, Long bookId) {
        this.orderId = orderId;
        this.bookId = bookId;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(
                Optional.ofNullable(orderId).orElse(0L),
                Optional.ofNullable(bookId).orElse(0L));
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        OrderBookId other = (OrderBookId) obj;
        return Objects.equals(orderId, other.orderId)
                && Objects.equals(bookId, other.bookId);
    }

}
