package ru.stqa.pft.addressbook.model;

import com.google.gson.annotations.Expose;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@XStreamAlias("group")
@Entity
@Table(name = "group_list")
public class GroupData {

//    @OneToOne(mappedBy = "groupName")
    @Expose
    @Column(name = "group_name")
    private  String name;

    @Expose
    @Column(name = "group_header")
    @Type(type = "text")
    private  String header;

    @Expose
    @Column(name = "group_footer")
    @Type(type = "text")
    private  String footer;


    @XStreamOmitField
    @Id
    @Column(name = "group_id")
    private  int id =  Integer.MAX_VALUE;



    @ManyToMany(mappedBy = "groups",fetch = FetchType.EAGER)
    private Set<ContactData> contacts = new HashSet<ContactData>();

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

        GroupData groupData = (GroupData) o;

        if (id != groupData.id) return false;
        if (name != null ? !name.equals(groupData.name) : groupData.name != null) return false;
        if (header != null ? !header.equals(groupData.header) : groupData.header != null) return false;
        return footer != null ? footer.equals(groupData.footer) : groupData.footer == null;

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (header != null ? header.hashCode() : 0);
        result = 31 * result + (footer != null ? footer.hashCode() : 0);
        result = 31 * result + id;
        return result;
    }

    public Contacts getContacts() {
        return new Contacts(contacts);

    }

    public String getName() {
        return name;
    }

    public int getId() {
        return id;
    }

    public String getHeader() {
        return header;
    }

    public String getFooter() {
        return footer;
    }

    public GroupData withId(int id) {

        this.id = id;
        return this;
    }

    public GroupData withName(String name) {
        this.name = name;
        return this;
    }

    public GroupData withHeader(String header) {
        this.header = header;
        return this;
    }

    public GroupData withFooter(String footer) {
        this.footer = footer;
        return this;
    }

    @Override
    public String toString() {
        return "GroupData{" +
                "name='" + name + '\'' +
                ", id='" + id + '\'' +
                '}';
    }


}

@@ -1163,647 +1163,124 @@
     
-if (id != groupData.id) return false;%0A        if (name != null ? !name.equals(groupData.name) : groupData.name != null) return false;%0A        if (header != null ? !header.equals(groupData.header) : groupData.header != null) return false;%0A        return footer != null ? footer.equals(groupData.footer) : groupData.footer == null;%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = name != null ? name.hashCode() : 0;%0A        result = 31 * result + (header != null ? header.hashCode() : 0);%0A        result = 31 * result + (footer != null ? footer.hashCode() : 0);%0A        result = 31 * result + id;%0A        return result
+return name.equals(groupData.name);%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return name.hashCode()
 ;%0A  

modify test