package com.sonymusic.dx.persistence.gras;

import jakarta.persistence.*;

import java.io.Serializable;

@Entity
@Table(name = "vgras005")
@IdClass(LocalProductPk.class)
public class LocalProduct extends RAASClientSpecificEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "country_key", nullable = false, length = 3, insertable = false, updatable = false)
    private String countryKey;

    @Id
    @Column(name = "loc_prod_no", nullable = false, length = 16)
    private String localProductNumber;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "country_key", insertable = false, updatable = false)
    private Country country;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "data_source_key")
    private DataSource dataSource;

    @Column(name = "is_confidential", nullable = false, length = 1)
    private String isConfidential;

    @Column(name = "local_barcode", length = 13)
    private String localBarcode;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "prod_no")
    private Product product;

    public String getCountryKey() {
        return countryKey;
    }

    public void setCountryKey(String countryKey) {
        this.countryKey = countryKey;
    }

    public String getLocalProductNumber() {
        return localProductNumber;
    }

    public void setLocalProductNumber(String localProductNumber) {
        this.localProductNumber = localProductNumber;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public String getIsConfidential() {
        return isConfidential;
    }

    public void setIsConfidential(String isConfidential) {
        this.isConfidential = isConfidential;
    }

    public String getLocalBarcode() {
        return localBarcode;
    }

    public void setLocalBarcode(String localBarcode) {
        this.localBarcode = localBarcode;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getCountryKey() == null) ? 0 : getCountryKey().hashCode());
        result = prime * result + ((getLocalProductNumber() == null) ? 0 : getLocalProductNumber().hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof LocalProduct))
            return false;
        LocalProduct other = (LocalProduct) obj;
        if (getCountryKey() == null) {
            if (other.getCountryKey() != null)
                return false;
        } else if (!getCountryKey().equals(other.getCountryKey()))
            return false;
        if (getLocalProductNumber() == null) {
            if (other.getLocalProductNumber() != null)
                return false;
        } else if (!getLocalProductNumber().equals(other.getLocalProductNumber()))
            return false;
        return true;
    }

}
