package com.oguerreiro.resilient.web.rest;

import java.net.URISyntaxException;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import com.oguerreiro.resilient.domain.PeriodVersion;
import com.oguerreiro.resilient.repository.PeriodVersionRepository;
import com.oguerreiro.resilient.service.PeriodVersionService;
import com.oguerreiro.resilient.service.dto.PeriodVersionDTO;

import jakarta.validation.Valid;

/**
 * REST controller for managing
 * {@link com.oguerreiro.resilient.domain.PeriodVersion}.
 */
//@RestController
//@RequestMapping("/api/period-versions")
public class PeriodVersionResource extends AbstractResilientResource<PeriodVersion, PeriodVersionDTO, Long> {

  private static final String ENTITY_NAME = "periodVersion";

  private final PeriodVersionService periodVersionService;

  public PeriodVersionResource(PeriodVersionService periodVersionService,
      PeriodVersionRepository periodVersionRepository) {
    super(PeriodVersion.class, periodVersionRepository, periodVersionService);
    this.periodVersionService = periodVersionService;
  }

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

  /* Override and Unsupport standard endpoints */
  /**
   * {@code POST  /period-versions} : Create a new entity.
   * UNSUPPORTED. CANT CREATE PeriodVersion's FROM FRONTEND
   */
  @Override
  @PreAuthorize("@resilientSecurity.canAccess()")
  @PostMapping("")
  public ResponseEntity<PeriodVersionDTO> create(@Valid PeriodVersionDTO domainDTO) throws URISyntaxException {
    log.debug("REST request to create PeriodVersion : {}", domainDTO);
    throw new UnsupportedOperationException();
  }

  /**
   * {@code PUT  /period-versions/:id} : Updates an existing entity.
   * UNSUPPORTED. CANT UPDATE PeriodVersion's FROM FRONTEND
   */
  @Override
  @PreAuthorize("@resilientSecurity.canAccess()")
  @PutMapping("/{id}")
  public ResponseEntity<PeriodVersionDTO> update(Long id, @Valid PeriodVersionDTO domainDTO) throws URISyntaxException {
    log.debug("REST request to update PeriodVersion : {}", domainDTO);
    throw new UnsupportedOperationException();
  }

  /**
   * {@code DELETE  /period-versions/:id} : delete entity by the "id".
   * UNSUPPORTED. CANT DELETE PeriodVersion's FROM FRONTEND
   */
  @Override
  @PreAuthorize("@resilientSecurity.canAccess()")
  @DeleteMapping("/{id}")
  public ResponseEntity<Void> delete(Long id) {
    log.debug("REST request to delete PeriodVersion");
    throw new UnsupportedOperationException();
  }

  /* PeriodVersionResource endpoints */
  /**
   * {@code GET  /period-versions/byPeriod/:periodId} : get all periodVersions for the giver periodId.
   *
   * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of units in body.
   */
  @GetMapping("/byPeriod/{periodId}")
  public List<PeriodVersionDTO> getAllByPeriod(@PathVariable("periodId") Long periodId) {
    log.debug("REST request to get all getAllByPeriod Id : {}", periodId);
    return periodVersionService.findAllByPeriod(periodId);
  }
}
