package com.kospo.talk.model;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.Hibernate;

import java.util.Objects;

@Getter
@Setter
@Embeddable
public class CodeId implements java.io.Serializable {
    private static final long serialVersionUID = -9144701466423603292L;
    @NotNull
    @Column(name = "id", nullable = false)
    private Integer id;

    @Size(max = 4)
    @NotNull
    @Column(name = "code", nullable = false, length = 4)
    private String code;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        CodeId entity = (CodeId) o;
        return Objects.equals(this.code, entity.code) &&
                Objects.equals(this.id, entity.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, id);
    }

}