package com.oguerreiro.resilient.web.rest;

import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
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.domain.VariableCategory;
import com.oguerreiro.resilient.repository.VariableCategoryRepository;
import com.oguerreiro.resilient.service.VariableCategoryService;
import com.oguerreiro.resilient.service.dto.VariableCategoryDTO;
import com.oguerreiro.resilient.service.mapper.VariableCategoryMapper;

/**
 * REST controller for managing {@link com.oguerreiro.resilient.domain.VariableCategory}.
 */
@RestController
@RequestMapping("/api/variable-categories")
public class VariableCategoryResource extends AbstractResilientResource<VariableCategory, VariableCategoryDTO, Long> {
  private static final String ENTITY_NAME = "variableCategory";

  private final VariableCategoryService variableCategoryService;

  public VariableCategoryResource(VariableCategoryService variableCategoryService,
      VariableCategoryRepository variableCategoryRepository, VariableCategoryMapper variableCategoryMapper) {
    super(VariableCategory.class, variableCategoryRepository, variableCategoryService);

    this.variableCategoryService = variableCategoryService;
  }

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

  @Override
  protected Sort getAllSort() {
    return Sort.by(Sort.Order.asc("variableScope.code"), Sort.Order.asc("code"));
  }

  /* VariableCategoryResource endpoints */
  /**
   * {@code GET /variable-categories/byScope/{:scopeId} : get all the VariableCategory within the scopeId.
   *
   * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of units in body.
   */
  @GetMapping("/byScope/{scopeId}")
  public List<VariableCategoryDTO> getAllByScope(@PathVariable("scopeId") Long scopeId) {
    log.debug("REST request to get all getAllByScope Id : {}", scopeId);
    return variableCategoryService.findAllByScope(scopeId, true);
  }

  /**
   * {@code GET /variable-categories/byScope/forData/{:scopeId} : get all the VariableCategory.
   *
   * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of units in body.
   */
  @GetMapping("/byScope/forData/{scopeId}")
  public List<VariableCategoryDTO> getAllByScopeForData(@PathVariable("scopeId") Long scopeId) {
    log.debug("REST request to get all getAllByScopeForData Id : {}", scopeId);
    return variableCategoryService.findAllByScope(scopeId, false);
  }

  /**
   * {@code GET /variable-categories/byScope/forFactor/{:scopeId} : get all the VariableCategory.
   *
   * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of units in body.
   */
  @GetMapping("/byScope/forFactor/{scopeId}")
  public List<VariableCategoryDTO> getAllByScopeForFactor(@PathVariable("scopeId") Long scopeId) {
    log.debug("REST request to get all getAllByScopeForFactor Id : {}", scopeId);
    return variableCategoryService.findAllByScopeForFactor(scopeId);
  }
}
