package com.sonymusic.dx.persistence.gras;

import jakarta.persistence.*;
import org.hibernate.type.YesNoConverter;

import java.io.Serializable;
import java.sql.Timestamp;

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

    @Id
    @Column(name = "prod_vers_no", nullable = false, insertable = false, updatable = false)
    private Long productVersionNo;

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

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "financ_label_key")
//    private FinancialLabelTier1 financialLabel;

    @Column(name = "is_confidential", nullable = false, length = 1)
    @Convert(converter = YesNoConverter.class)
    private boolean isConfidential;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({ @JoinColumn(name = "label_key", referencedColumnName = "label_key"), @JoinColumn(name = "label_ext", referencedColumnName = "label_ext") })
    private Label label;

    @Column(name = "loc_financ_project_no", length = 20)
    private String localFinancialProjectNo;

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumns({ @JoinColumn(name = "loc_genre_key", referencedColumnName = "loc_genre_key", insertable = false, updatable = false),
//            @JoinColumn(name = "country_key", referencedColumnName = "country_key", insertable = false, updatable = false) })
//    private LocalGenre localGenre;

    @Column(name = "loc_prod_title", length = 250)
    private String localProductTitle;

    @Column(name = "log_mod_stamp", nullable = false)
    private Timestamp lastLogicalModificationTime;

    @Column(name = "log_mod_user", nullable = false, length = 8)
    private String lastLogicalModificationUser;

    @Column(name = "omit_from_flor_updates", nullable = false, length = 1)
    private boolean omitFromFlorUpdates;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "strategic_rep_grp_key")
    private StrategicReportingGroup strategicReportingGroup;

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "prod_vers_no", insertable = false, updatable = false)
    private ProductVersion productVersion;


    public boolean isConfidential() {
        return isConfidential;
    }

    public void setConfidential(boolean isConfidential) {
        this.isConfidential = isConfidential;
    }

    public Label getLabel() {
        return label;
    }

    public void setLabel(Label label) {
        this.label = label;
    }

    public String getLocalFinancialProjectNo() {
        return localFinancialProjectNo;
    }

    public void setLocalFinancialProjectNo(String localFinancialProjectNo) {
        this.localFinancialProjectNo = localFinancialProjectNo;
    }

    public String getLocalProductTitle() {
        return localProductTitle;
    }

    public void setLocalProductTitle(String localProductTitle) {
        this.localProductTitle = localProductTitle;
    }

    public Timestamp getLastLogicalModificationTime() {
        return lastLogicalModificationTime;
    }

    public void setLastLogicalModificationTime(Timestamp lastLogicalModificationTime) {
        this.lastLogicalModificationTime = lastLogicalModificationTime;
    }

    public String getLastLogicalModificationUser() {
        return lastLogicalModificationUser;
    }

    public void setLastLogicalModificationUser(String lastLogicalModificationUser) {
        this.lastLogicalModificationUser = lastLogicalModificationUser;
    }

    public boolean isOmitFromFlorUpdates() {
        return omitFromFlorUpdates;
    }

    public void setOmitFromFlorUpdates(boolean omitFromFlorUpdates) {
        this.omitFromFlorUpdates = omitFromFlorUpdates;
    }

    public StrategicReportingGroup getStrategicReportingGroup() {
        return strategicReportingGroup;
    }

    public void setStrategicReportingGroup(StrategicReportingGroup strategicReportingGroup) {
        this.strategicReportingGroup = strategicReportingGroup;
    }

    public Country getCountry() {
        return country;
    }

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

    public ProductVersion getProductVersion() {
        return productVersion;
    }

    public void setProductVersion(ProductVersion productVersion) {
        this.productVersion = productVersion;
    }

    protected Long getProductVersionNo() {
        return productVersionNo;
    }

    protected void setProductVersionNo(Long productVersionNo) {
        this.productVersionNo = productVersionNo;
    }

    protected String getCountryKey() {
        return countryKey;
    }

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

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

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

}