package com.sonymusic.dx.persistence.gras;

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

import java.io.Serializable;

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

    @Id
    @Column(name = "track_no", nullable = false, length = 17, insertable = false, updatable = false)
    private String trackNo;

    @Id
    @Column(name = "track_ext", nullable = false, length = 2, insertable = false, updatable = false)
    private String trackExt;

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

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

    @Id
    @Column(name = "id_no", nullable = false)
    private Long idNo;

    @Column(name = "seq_no", nullable = false)
    private Long sequenceNo;

    @Column(name = "associated_to", length = 250)
    private String associatedTo;

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

    @Column(name = "is_main_artist", length = 1)
    @Convert(converter = YesNoConverter.class)
    private Boolean isMainArtist;

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "link_word_key")
//    private ArtworkLinkingWord linkingWord;

    @Column(name = "mod_particip_name", length = 250)
    private String modParticipName;

    @Column(name = "mod_task_type_name", length = 250)
    private String modTaskTypeName;

    @Column(name = "particip_role", length = 250)
    private String participRole;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumns({ @JoinColumn(name = "track_no", referencedColumnName = "track_no", insertable = false, updatable = false, nullable = false),
            @JoinColumn(name = "track_ext", referencedColumnName = "track_ext", insertable = false, updatable = false, nullable = false) })
    private Track track;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(name = "particip_no", referencedColumnName = "particip_no", insertable = false, updatable = false, nullable = false)
    private Participant participant;

//    @ManyToOne(optional = false, fetch = FetchType.LAZY)
//    @JoinColumn(name = "task_type_key", insertable = false, updatable = false, nullable = false)
//    private TaskType taskType;

    @Column(name = "is_primary_artist", length = 1)
    @Convert(converter = YesNoConverter.class)
    private Boolean isPrimArtist;

    @Column(name = "do_not_display_flag", length = 1)
    @Convert(converter = YesNoConverter.class)
    private Boolean doNotDisplayFlag;

    public Boolean getIsPrimArtist() {
        return isPrimArtist;
    }

    public void setIsPrimArtist(Boolean isPrimArtist) {
        this.isPrimArtist = isPrimArtist;
    }

    protected String getTrackNo() {
        return trackNo;
    }

    protected void setTrackNo(String trackNo) {
        this.trackNo = trackNo;
    }

    protected String getTrackExt() {
        return trackExt;
    }

    protected void setTrackExt(String trackExt) {
        this.trackExt = trackExt;
    }

    protected Long getParticipantNo() {
        return participantNo;
    }

    protected void setParticipantNo(Long participantNo) {
        this.participantNo = participantNo;
    }

    protected String getTaskTypeKey() {
        return taskTypeKey;
    }

    protected void setTaskTypeKey(String taskTypeKey) {
        this.taskTypeKey = taskTypeKey;
    }

    public Long getIdNo() {
        return idNo;
    }

    public void setIdNo(Long idNo) {
        this.idNo = idNo;
    }

    public Long getSequenceNo() {
        return sequenceNo;
    }

    public void setSequenceNo(Long sequenceNo) {
        this.sequenceNo = sequenceNo;
    }

    public String getAssociatedTo() {
        return associatedTo;
    }

    public void setAssociatedTo(String associatedTo) {
        this.associatedTo = associatedTo;
    }

    public boolean isConfidential() {
        return isConfidential;
    }

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

    public Boolean getIsMainArtist() {
        if (isMainArtist == null)
            return false;

        return isMainArtist;
    }

    public void setIsMainArtist(Boolean isMainArtist) {
        this.isMainArtist = isMainArtist;
    }

//    public ArtworkLinkingWord getLinkingWord() {
//        return linkingWord;
//    }
//
//    public void setLinkingWord(ArtworkLinkingWord linkingWord) {
//        this.linkingWord = linkingWord;
//    }

    public String getModParticipName() {
        return modParticipName;
    }

    public void setModParticipName(String modParticipName) {
        this.modParticipName = modParticipName;
    }

    public String getModTaskTypeName() {
        return modTaskTypeName;
    }

    public void setModTaskTypeName(String modTaskTypeName) {
        this.modTaskTypeName = modTaskTypeName;
    }

    public String getParticipRole() {
        return participRole;
    }

    public void setParticipRole(String participRole) {
        this.participRole = participRole;
    }

    public Track getTrack() {
        return track;
    }

    public void setTrack(Track track) {
        this.track = track;
    }

    public Participant getParticipant() {
        return participant;
    }

    public void setParticipant(Participant participant) {
        this.participant = participant;
    }

//    public TaskType getTaskType() {
//        return taskType;
//    }
//
//    public void setTaskType(TaskType taskType) {
//        this.taskType = taskType;
//    }

    public Boolean getDoNotDisplayFlag() {
        return doNotDisplayFlag;
    }

    public void setDoNotDisplayFlag(Boolean doNotDisplayFlag) {
        this.doNotDisplayFlag = doNotDisplayFlag;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getIdNo() == null) ? 0 : getIdNo().hashCode());
        result = prime * result + ((getParticipantNo() == null) ? 0 : getParticipantNo().hashCode());
        result = prime * result + ((getTaskTypeKey() == null) ? 0 : getTaskTypeKey().hashCode());
        result = prime * result + ((getTrackExt() == null) ? 0 : getTrackExt().hashCode());
        result = prime * result + ((getTrackNo() == null) ? 0 : getTrackNo().hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof TrackParticipant))
            return false;
        TrackParticipant other = (TrackParticipant) obj;
        if (getIdNo() == null) {
            if (other.getIdNo() != null)
                return false;
        } else if (!getIdNo().equals(other.getIdNo()))
            return false;
        if (getParticipantNo() == null) {
            if (other.getParticipantNo() != null)
                return false;
        } else if (!getParticipantNo().equals(other.getParticipantNo()))
            return false;
        if (getTaskTypeKey() == null) {
            if (other.getTaskTypeKey() != null)
                return false;
        } else if (!getTaskTypeKey().equals(other.getTaskTypeKey()))
            return false;
        if (getTrackExt() == null) {
            if (other.getTrackExt() != null)
                return false;
        } else if (!getTrackExt().equals(other.getTrackExt()))
            return false;
        if (getTrackNo() == null) {
            if (other.getTrackNo() != null)
                return false;
        } else if (!getTrackNo().equals(other.getTrackNo()))
            return false;
        return true;
    }

}