package marketing.heyday.hartmann.fotodocumentation.core.model;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import jakarta.persistence.*;

/**
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 19 Jan 2026
 */

@Entity
@Table(name = "x_right")
public class Right extends AbstractDateEntity {
	private static final long serialVersionUID = 1L;
	public static final String SEQUENCE = "right_seq";
	
	@Id
	@Column(name = "right_id", length = 22)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQUENCE)
	@SequenceGenerator(name = SEQUENCE, sequenceName = SEQUENCE, allocationSize = 1)
	private Long rightId;

	@Column(nullable = false, unique = true)
	private String code;

	@Column(nullable = false, unique = true)
	private String name;

	@ManyToMany(mappedBy = "rights")
	private Set<User> roles = new HashSet<>();

	public Long getRightId() {
		return rightId;
	}

	public void setRightId(Long rightId) {
		this.rightId = rightId;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(code).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || this.getClass() != obj.getClass()) {
			return false;
		}
		return this.code.equals(((Right) obj).getCode());
	}

	public static class Builder {
		private Right instance = new Right();

		public Builder code(String code) {
			instance.setCode(code);
			return this;
		}

		public Builder name(String name) {
			instance.setName(name);
			return this;
		}

		public Right build() {
			return instance;
		}
	}
}