package com.oguerreiro.resilient.security.resillient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.oguerreiro.resilient.domain.AbstractResilientLongIdEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

/**
 * SecurityGroupPermission
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "security_group_permission")
public class SecurityGroupPermission extends AbstractResilientLongIdEntity<SecurityGroupPermission> {
  private static final long serialVersionUID = 1L;

  @ManyToOne(fetch = FetchType.LAZY)
  @JsonIgnoreProperties(value = { "securityGroupPermissions" }, allowSetters = true)
  private SecurityGroup securityGroup;

  @ManyToOne(fetch = FetchType.LAZY)
  private SecurityResource securityResource;

  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "create_permission", nullable = false)
  private SecurityPermission createPermission;

  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "read_permission", nullable = false)
  private SecurityPermission readPermission;

  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "update_permission", nullable = false)
  private SecurityPermission updatePermission;

  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "delete_permission", nullable = false)
  private SecurityPermission deletePermission;

  public SecurityGroup getSecurityGroup() {
    return this.securityGroup;
  }

  public void setSecurityGroup(SecurityGroup securityGroup) {
    this.securityGroup = securityGroup;
  }

  public SecurityGroupPermission securityGroup(SecurityGroup securityGroup) {
    this.setSecurityGroup(securityGroup);
    return this;
  }

  public SecurityResource getSecurityResource() {
    return this.securityResource;
  }

  public void setSecurityResource(SecurityResource securityResource) {
    this.securityResource = securityResource;
  }

  public SecurityGroupPermission securityResource(SecurityResource securityResource) {
    this.setSecurityResource(securityResource);
    return this;
  }

  public SecurityPermission getCreatePermission() {
    return createPermission;
  }

  public SecurityGroupPermission createPermission(SecurityPermission createPermission) {
    this.setCreatePermission(createPermission);
    return this;
  }

  public void setCreatePermission(SecurityPermission createPermission) {
    this.createPermission = createPermission;
  }

  public SecurityPermission getReadPermission() {
    return readPermission;
  }

  public SecurityGroupPermission readPermission(SecurityPermission readPermission) {
    this.setReadPermission(readPermission);
    return this;
  }

  public void setReadPermission(SecurityPermission readPermission) {
    this.readPermission = readPermission;
  }

  public SecurityPermission getUpdatePermission() {
    return updatePermission;
  }

  public SecurityGroupPermission updatePermission(SecurityPermission updatePermission) {
    this.setUpdatePermission(updatePermission);
    return this;
  }

  public void setUpdatePermission(SecurityPermission updatePermission) {
    this.updatePermission = updatePermission;
  }

  public SecurityPermission getDeletePermission() {
    return deletePermission;
  }

  public SecurityGroupPermission deletePermission(SecurityPermission deletePermission) {
    this.setDeletePermission(deletePermission);
    return this;
  }

  public void setDeletePermission(SecurityPermission deletePermission) {
    this.deletePermission = deletePermission;
  }

  //@formatter:off
  @Override
  public String toString() {
    return "SecurityGroup{" + 
              "id=" + getId() + 
              ", createPermission='" + getCreatePermission() + "'" + 
              ", readPermission='" + getReadPermission() + "'" +
              ", updatePermission='" + getUpdatePermission() + "'" +
              ", deletePermission='" + getDeletePermission() + "'" +
              ", version=" + getVersion()
        + "}";
  }
  //@formatter:on
}
