package io.gmss.fiscad.entities.user;

import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.enums.UserRole;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Objects;

//@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Role extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Enumerated(EnumType.STRING)
    private UserRole nom;
    private String description;

    public Role(UserRole name, String description) {
        this.nom = name;
        this.description = description;
    }

    @Override
    public boolean equals(Object o) {

        // If the object is compared with itself then return true
        if (o == this) {
            return true;
        }

        /* Check if o is an instance of Complex or not
          "null instanceof [type]" also returns false */
        if (!(o instanceof Role)) {
            return false;
        }

        // typecast o to Complex so that we can compare data members
        Role r = (Role) o;

        // Compare the data members and return accordingly
        return r.getNom().equals(this.getNom());
    }

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