package samuelb.capripol;

import javax.persistence.*;
import java.util.Objects;

@Entity(name = "GroupUserRoles")
public class GroupUserRoles {

    @EmbeddedId
    private GroupUserRolesID id;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("groupRoleID")
    private GroupRole groupRole;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("groupID")
    private Group group;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("userID")
    private User user;

    public GroupUserRoles(){}

    public GroupUserRoles(GroupRole groupRole, Group group, User user) {
        this.groupRole = groupRole;
        this.group = group;
        this.user = user;
        this.id = new GroupUserRolesID(groupRole.getId(), group.getGroupID(), user.getUserId());
    }

    public GroupUserRolesID getId() {
        return id;
    }

    public void setId(GroupUserRolesID id) {
        this.id = id;
    }

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public GroupRole getGroupRole() {
        return groupRole;
    }

    public void setGroupRole(GroupRole groupRole) {
        this.groupRole = groupRole;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass())
            return false;

        GroupUserRoles that = (GroupUserRoles) o;
        return Objects.equals(groupRole, that.groupRole) &&
                Objects.equals(group, that.group) &&
                Objects.equals(user, that.user);
    }

    @Override
    public int hashCode() {
        return Objects.hash(groupRole, group, user);
    }
}
