package com.sonymusic.dx.persistence.gras;

import java.io.Serializable;
import java.util.List;

import org.hibernate.type.YesNoConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OrderColumn;
import jakarta.persistence.Table;

@Entity
@Table(name = "vgras003")
@IdClass(ProductComponentPk.class)
public class ProductComponent extends RAASClientSpecificEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "component_no", nullable = false)
	private Long componentNumber;

	@Id
	@Column(name = "prod_no", nullable = false, length = 14, insertable = false, updatable = false)
	private String productNumber;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "config_key")
	private Configuration configuration;

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

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

	@Column(name = "no_of_tracks", nullable = false)
	private Long numberOfTracks;

	@Column(name = "p_line", length = 250)
	private String pLine;

	@Column(name = "play_time_a")
	private Long playTimeA;

	@Column(name = "play_time_b")
	private Long playTimeB;

	@Column(name = "prod_info_a_tid")
	private Long productInfoATId;

	@ElementCollection
	@Column(name = "text_part")
	@JoinTable(name = "vgras029", joinColumns = @JoinColumn(name = "text_id", referencedColumnName = "prod_info_a_tid"))
	@OrderColumn(name = "seq_no")
	private List<String> productInfoA;

	@Column(name = "prod_info_b_tid")
	private Long productInfoBTId;

	@ElementCollection
	@Column(name = "text_part")
	@JoinTable(name = "vgras029", joinColumns = @JoinColumn(name = "text_id", referencedColumnName = "prod_info_b_tid"))
	@OrderColumn(name = "seq_no")
	private List<String> productInfoB;

	@ManyToOne(optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "prod_no", insertable = false, updatable = false)
	private Product product;

	@Column(name = "scribe_no_a", length = 50)
	private String scribeNumberA;

	@Column(name = "component_id")
	private String componentID;

	@Column(name = "scribe_no_b", length = 50)
	private String scribeNumberB;

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

	@Column(name = "rev_alloc_percent")
	private Double revAllocPercent;

//    @OneToMany(mappedBy = "productComponent", fetch = FetchType.LAZY)
//    private List<ProductTrack> productTracks = new ArrayList<ProductTrack>();

	public Long getComponentNumber() {
		return componentNumber;
	}

	public void setComponentNumber(Long componentNumber) {
		this.componentNumber = componentNumber;
	}

	protected String getProductNumber() {
		return productNumber;
	}

	protected void setProductNumber(String productNumber) {
		this.productNumber = productNumber;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public boolean isHasDiffPlatform() {
		return hasDiffPlatform;
	}

	public void setHasDiffPlatform(boolean hasDiffPlatform) {
		this.hasDiffPlatform = hasDiffPlatform;
	}

	public boolean isConfidential() {
		return isConfidential;
	}

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

	public Long getNumberOfTracks() {
		return numberOfTracks;
	}

	public void setNumberOfTracks(Long numberOfTracks) {
		this.numberOfTracks = numberOfTracks;
	}

	public String getpLine() {
		return pLine;
	}

	public void setpLine(String pLine) {
		this.pLine = pLine;
	}

	public Long getPlayTimeA() {
		return playTimeA;
	}

	public void setPlayTimeA(Long playTimeA) {
		this.playTimeA = playTimeA;
	}

	public Long getPlayTimeB() {
		return playTimeB;
	}

	public void setPlayTimeB(Long playTimeB) {
		this.playTimeB = playTimeB;
	}

	public List<String> getProductInfoA() {
		return productInfoA;
	}

	public void setProductInfoA(List<String> productInfoA) {
		this.productInfoA = productInfoA;
	}

	public List<String> getProductInfoB() {
		return productInfoB;
	}

	public void setProductInfoB(List<String> productInfoB) {
		this.productInfoB = productInfoB;
	}

	public Product getProduct() {
		return product;
	}

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

	public String getScribeNumberA() {
		return scribeNumberA;
	}

	public void setScribeNumberA(String scribeNumberA) {
		this.scribeNumberA = scribeNumberA;
	}

	public String getScribeNumberB() {
		return scribeNumberB;
	}

	public void setScribeNumberB(String scribeNumberB) {
		this.scribeNumberB = scribeNumberB;
	}

	public boolean isTimesAreGenerated() {
		return timesAreGenerated;
	}

	public void setTimesAreGenerated(boolean timesAreGenerated) {
		this.timesAreGenerated = timesAreGenerated;
	}

	protected Long getProductInfoATId() {
		return productInfoATId;
	}

	protected void setProductInfoATId(Long productInfoATId) {
		this.productInfoATId = productInfoATId;
	}

	protected Long getProductInfoBTId() {
		return productInfoBTId;
	}

	protected void setProductInfoBTId(Long productInfoBTId) {
		this.productInfoBTId = productInfoBTId;
	}

//    public List<ProductTrack> getProductTracks() {
//        return productTracks;
//    }
//
//    public void setProductTracks(List<ProductTrack> productTracks) {
//        this.productTracks = productTracks;
//    }

	public String getComponentID() {
		return componentID;
	}

	public void setComponentID(String componentID) {
		this.componentID = componentID;
	}

	public void setRevAllocPercent(Double revAllocPercent) {
		this.revAllocPercent = revAllocPercent;
	}

	public Double getRevAllocPercent() {
		return revAllocPercent;
	}

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

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

}