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.ResilientLog;
import com.oguerreiro.resilient.repository.ResilientLogRepository;
import com.oguerreiro.resilient.service.ResilientLogService;
import com.oguerreiro.resilient.service.dto.ResilientLogDTO;

import jakarta.validation.Valid;

/**
 * REST controller for managing {@link com.oguerreiro.resilient.domain.ResilientLog}.
 */
@RestController
@RequestMapping("/api/resilient-logs")
public class ResilientLogResource extends AbstractResilientResource<ResilientLog, ResilientLogDTO, Long> {

  private static final String ENTITY_NAME = "resilientLog";

  private final ResilientLogService resilientLogService;

  private final ResilientLogRepository resilientLogRepository;

  public ResilientLogResource(ResilientLogService inputDataUploadLogService,
      ResilientLogRepository inputDataUploadLogRepository) {
    super(ResilientLog.class, inputDataUploadLogRepository, inputDataUploadLogService);
    this.resilientLogService = inputDataUploadLogService;
    this.resilientLogRepository = inputDataUploadLogRepository;
  }

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

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

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

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

  /* ResilientLogResource endpoints */
  /**
   * {@code GET  /resilient-logs} : get all the resilientLogs.
   *
   * @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 resilientLogs in
   *                   body.
   */
  @GetMapping("/owner/{id}")
  public List<ResilientLogDTO> getAllResilientLogsByOwner(@PathVariable(value = "id", required = false) final Long id) {
    log.debug("REST request to get all ResilientLogs By Owner : {}", id);
    return resilientLogService.findAllByOwnerId(id);
  }
}
