package com.oguerreiro.resilient.security.resillient;

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.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
 * SecurityResource
 */
@Entity
@Table(name = "security_resource")
public class SecurityResource extends AbstractResilientLongIdEntity<SecurityResource> {
  private static final long serialVersionUID = 1L;

  /**
   * User defined code. Must be unique.
   */
  @NotNull
  @Size(min = 3)
  @Column(name = "code", nullable = false, unique = true)
  private String code;

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

  /**
   * The type of resource
   */
  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "type", nullable = false)
  private SecurityResourceType type;

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

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

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

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

  public String getCode() {
    return code;
  }

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

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

  public String getName() {
    return name;
  }

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

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

  public SecurityResourceType getType() {
    return type;
  }

  public SecurityResource type(SecurityResourceType type) {
    this.setType(type);
    return this;
  }

  public void setType(SecurityResourceType type) {
    this.type = type;
  }

  public SecurityPermission getDefaultCreatePermission() {
    return defaultCreatePermission;
  }

  public SecurityResource defaultCreatePermission(SecurityPermission defaultCreatePermission) {
    this.setDefaultCreatePermission(defaultCreatePermission);
    return this;
  }

  public void setDefaultCreatePermission(SecurityPermission defaultCreatePermission) {
    this.defaultCreatePermission = defaultCreatePermission;
  }

  public SecurityPermission getDefaultReadPermission() {
    return defaultReadPermission;
  }

  public SecurityResource defaultReadPermission(SecurityPermission defaultReadPermission) {
    this.setDefaultReadPermission(defaultReadPermission);
    return this;
  }

  public void setDefaultReadPermission(SecurityPermission defaultReadPermission) {
    this.defaultReadPermission = defaultReadPermission;
  }

  public SecurityPermission getDefaultUpdatePermission() {
    return defaultUpdatePermission;
  }

  public SecurityResource defaultUpdatePermission(SecurityPermission defaultUpdatePermission) {
    this.setDefaultUpdatePermission(defaultUpdatePermission);
    return this;
  }

  public void setDefaultUpdatePermission(SecurityPermission defaultUpdatePermission) {
    this.defaultUpdatePermission = defaultUpdatePermission;
  }

  public SecurityPermission getDefaultDeletePermission() {
    return defaultDeletePermission;
  }

  public SecurityResource defaultDeletePermission(SecurityPermission defaultDeletePermission) {
    this.setDefaultDeletePermission(defaultDeletePermission);
    return this;
  }

  public void setDefaultDeletePermission(SecurityPermission defaultDeletePermission) {
    this.defaultDeletePermission = defaultDeletePermission;
  }

  //@formatter:off
  @Override
  public String toString() {
    return "SecurityResource{" + 
              "id=" + getId() + 
              ", code='" + getCode() + "'" +
              ", name='" + getName() + "'" + 
              ", type='" + getType() + "'" +
              ", defaultCreatePermission='" + getDefaultCreatePermission() + "'" + 
              ", defaultReadPermission='" + getDefaultReadPermission() + "'" +
              ", defaultUpdatePermission='" + getDefaultUpdatePermission() + "'" +
              ", defaultDeletePermission='" + getDefaultDeletePermission() + "'" +
              ", version=" + getVersion()
        + "}";
  }
  //@formatter:on
}
