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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.oguerreiro.resilient.domain.InputDataUploadLog;
import com.oguerreiro.resilient.repository.InputDataUploadLogRepository;
import com.oguerreiro.resilient.service.InputDataUploadLogService;
import com.oguerreiro.resilient.service.dto.InputDataUploadLogDTO;

import jakarta.validation.Valid;

/**
 * REST controller for managing {@link com.oguerreiro.resilient.domain.InputDataUploadLog}.
 */
@RestController
@RequestMapping("/api/input-data-upload-logs")
public class InputDataUploadLogResource
    extends AbstractResilientResource<InputDataUploadLog, InputDataUploadLogDTO, Long> {

  private static final String ENTITY_NAME = "inputDataUploadLog";

  private final InputDataUploadLogService inputDataUploadLogService;

  private final InputDataUploadLogRepository inputDataUploadLogRepository;

  public InputDataUploadLogResource(InputDataUploadLogService inputDataUploadLogService,
      InputDataUploadLogRepository inputDataUploadLogRepository) {
    super(InputDataUploadLog.class, inputDataUploadLogRepository, inputDataUploadLogService);
    this.inputDataUploadLogService = inputDataUploadLogService;
    this.inputDataUploadLogRepository = inputDataUploadLogRepository;
  }

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

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

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

  /**
   * {@code DELETE  /input-data-upload-logs/:id} : delete entity by the "id".
   * UNSUPPORTED. CANT DELETE InputDataUploadLog FROM FRONTEND
   */
  @Override
  @PreAuthorize("@resilientSecurity.canAccess()")
  @DeleteMapping("/{id}")
  public ResponseEntity<Void> delete(Long id) {
    log.debug("REST request to delete InputDataUploadLog : {}", id);
    throw new UnsupportedOperationException();
  }

  /* InputDataUploadLogResource endpoints */
  /**
   * {@code GET  /input-data-upload-logs} : get all the inputDataUploadLogs.
   *
   * @param  eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
   * @return           the {@link ResponseEntity} with status {@code 200 (OK)} and the list of inputDataUploadLogs in
   *                   body.
   */
  @GetMapping("/owner/{id}")
  public List<InputDataUploadLogDTO> getAllInputDataUploadLogsByOwner(
      @PathVariable(value = "id", required = false) final Long id) {
    log.debug("REST request to get all InputDataUploadLogs By Owner : {}", id);
    return inputDataUploadLogService.findAllByOwner(id);
  }
}
