package com.oguerreiro.resilient.web.rest.security;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.oguerreiro.resilient.repository.security.SecurityGroupRepository;
import com.oguerreiro.resilient.security.resillient.SecurityGroup;
import com.oguerreiro.resilient.service.dto.security.SecurityGroupDTO;
import com.oguerreiro.resilient.service.dto.security.SecurityGroupPermissionDTO;
import com.oguerreiro.resilient.service.security.SecurityGroupService;
import com.oguerreiro.resilient.web.rest.AbstractResilientResource;

/**
 * REST controller for managing {@link com.oguerreiro.resilient.security.SecurityGroup}.
 */
@RestController
@RequestMapping("/api/security/groups")
public class SecurityGroupResource extends AbstractResilientResource<SecurityGroup, SecurityGroupDTO, Long> {

  private static final String ENTITY_NAME = "SecurityGroup";
  private final SecurityGroupService securityGroupService;

  public SecurityGroupResource(SecurityGroupRepository securityGroupRepository,
      SecurityGroupService securityGroupService) {
    super(SecurityGroup.class, securityGroupRepository, securityGroupService);

    this.securityGroupService = securityGroupService;
  }

  /* Abstract methods impl*/
  @Override
  protected String getEntityName() {
    return ENTITY_NAME;
  }

  /* DashboardResource endpoints */
  @GetMapping("/{id}/permissions")
  public List<SecurityGroupPermissionDTO> getSecurityGroupPermissions(@PathVariable("id") Long securityGroupid) {
    log.debug("REST request to getSecurityGroupPermissions " + this.getClass().getSimpleName() + "'s.");
    return securityGroupService.findPermissionsFor(securityGroupid);
  }
}
