package com.oguerreiro.resilient.service.dto.security;

import com.oguerreiro.resilient.security.resillient.SecurityGroupPermission;
import com.oguerreiro.resilient.security.resillient.SecurityPermission;
import com.oguerreiro.resilient.service.dto.AbstractResilientDTO;

import io.swagger.v3.oas.annotations.media.Schema;

/**
 * A DTO for the {@link com.oguerreiro.resilient.security.SecurityGroupPermission} entity.
 */
@Schema(description = "SecurityGroupPermission")
public class SecurityGroupPermissionDTO extends AbstractResilientDTO<Long> {

  private static final long serialVersionUID = 1L;

  private SecurityGroupDTO securityGroup;
  private SecurityResourceDTO securityResource;
  private SecurityPermission createPermission;
  private SecurityPermission readPermission;
  private SecurityPermission updatePermission;
  private SecurityPermission deletePermission;

  // Needed for Jackson
  public SecurityGroupPermissionDTO() {
  }

  public SecurityGroupPermissionDTO(SecurityGroupPermission securityGroupPermission) {
    // Don't know why I need this. In some cases the collection.stream() invoques the mapper with a NULL ??!!
    if (securityGroupPermission == null) {
      return;
    }
    this.securityResource = new SecurityResourceDTO();
    this.securityResource.setCode(securityGroupPermission.getSecurityResource().getCode());

    this.createPermission = securityGroupPermission.getCreatePermission();
    this.readPermission = securityGroupPermission.getReadPermission();
    this.updatePermission = securityGroupPermission.getUpdatePermission();
    this.deletePermission = securityGroupPermission.getDeletePermission();
  }

  public SecurityGroupDTO getSecurityGroup() {
    return securityGroup;
  }

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

  public SecurityResourceDTO getSecurityResource() {
    return securityResource;
  }

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

  public SecurityPermission getCreatePermission() {
    return createPermission;
  }

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

  public SecurityPermission getReadPermission() {
    return readPermission;
  }

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

  public SecurityPermission getUpdatePermission() {
    return updatePermission;
  }

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

  public SecurityPermission getDeletePermission() {
    return deletePermission;
  }

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

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