package com.griddynamics.jagger.jaas.storage.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.io.Serializable;

/**
 * This entity represents Test Suite configuration. Currently it has only testSuiteId field, but in future it will be extended
 * with more fields.
 */
@Entity
@Table(name = "test_suite_entity", uniqueConstraints = @UniqueConstraint(columnNames = {"`test_suite_id`", "`environment_id`"}))
public class TestSuiteEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @Column(name = "`test_suite_id`", nullable = false)
    private String testSuiteId;

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "`environment_id`")
    private TestEnvironmentEntity testEnvironmentEntity;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTestSuiteId() {
        return testSuiteId;
    }

    public void setTestSuiteId(String testSuiteId) {
        this.testSuiteId = testSuiteId;
    }

    public TestEnvironmentEntity getTestEnvironmentEntity() {
        return testEnvironmentEntity;
    }

    public void setTestEnvironmentEntity(TestEnvironmentEntity testEnvironmentEntity) {
        this.testEnvironmentEntity = testEnvironmentEntity;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TestSuiteEntity that = (TestSuiteEntity) o;

        if (testSuiteId != null ? !testSuiteId.equals(that.testSuiteId) : that.testSuiteId != null) return false;
        String envId = testEnvironmentEntity != null ? testEnvironmentEntity.getEnvironmentId() : null;
        String thatEnvId = that.testEnvironmentEntity != null ? that.testEnvironmentEntity.getEnvironmentId() : null;
        return envId != null ? envId.equals(thatEnvId) : thatEnvId == null;

    }

    @Override
    public int hashCode() {
        int result = testSuiteId != null ? testSuiteId.hashCode() : 0;
        String envId = testEnvironmentEntity != null ? testEnvironmentEntity.getEnvironmentId() : null;
        result = 31 * result + (envId != null ? envId.hashCode() : 0);
        return result;
    }
}

@@ -2619,11 +2619,300 @@
 t;%0A    %7D
+%0A%0A    @Override%0A    public String toString() %7B%0A        return %22TestSuiteEntity%7B%22 +%0A                %22testSuiteId='%22 + testSuiteId + '%5C'' +%0A                %22, testEnvironmentId=%22 + (testEnvironmentEntity != null ? testEnvironmentEntity.getEnvironmentId() : null) +%0A                '%7D';%0A    %7D
 %0A%7D%0A

Add toString to TestSuiteEntity