package com.jakubu9333.grammarManager.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;

/**
 * @author Jakub Uhlarik
 */

@Entity
@Getter
@Setter
@NoArgsConstructor
public class RightSidePart {

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

    @JsonView(View.All.class)
    @Column(columnDefinition = "text")
    private String part;

    @JsonCreator
    public RightSidePart(@JsonProperty("id") Long id, @JsonProperty("part") String part) {
        this(part);
    }

    public RightSidePart(String part) {
        this.part = part;
    }

    public RightSidePart(RightSidePart p) {
        this.id = null;
        this.part = p.getPart();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RightSidePart that = (RightSidePart) o;
        return Objects.equals(part, that.part);
    }

    @Override
    public int hashCode() {
        return Objects.hash(part);
    }
}
