package ec.edu.espe.movilidad.MovilidadWS.Controller;

import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTPlanificacion;
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTPlanificacion.IServiceUzyTPlanificacion;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import static ec.edu.espe.movilidad.MovilidadWS.Constant.GlobalConstants.V1_API_VERSION;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping(V1_API_VERSION + "/planificacion")

public class UzyTPlanificacionController {

    private final IServiceUzyTPlanificacion serviceUzyTPlanificacion;

    public UzyTPlanificacionController(IServiceUzyTPlanificacion serviceUzyTPlanificacion) {
        this.serviceUzyTPlanificacion = serviceUzyTPlanificacion;
    }

    @GetMapping("/exampleFindId/{id}")
    public ResponseEntity<DtoUzyTPlanificacion> ListarPorID(@PathVariable Long id) {
        return new ResponseEntity<>(serviceUzyTPlanificacion.ListarPorID(id), HttpStatus.OK);
    }

    @GetMapping("/getAll")
    public ResponseEntity<List<DtoUzyTPlanificacion>> ListarRegistros() {
        return new ResponseEntity<>(serviceUzyTPlanificacion.ListarRegistros(), HttpStatus.OK);
    }

    @PostMapping("/guardar")
    public ResponseEntity<DtoUzyTPlanificacion> guardar(@RequestBody DtoUzyTPlanificacion dtoUzyTPlanificacion) {
        return new ResponseEntity<>(serviceUzyTPlanificacion.guardar(dtoUzyTPlanificacion), HttpStatus.OK);
    }

    @PutMapping("/editar/{id}")
    public ResponseEntity<DtoUzyTPlanificacion> editar(@PathVariable Long id,
                                                       @RequestBody DtoUzyTPlanificacion dtoUzyTPlanificacion) {
        return new ResponseEntity<>(serviceUzyTPlanificacion.editar(id, dtoUzyTPlanificacion), HttpStatus.OK);

    }

    @DeleteMapping("/eliminar/{id}")
    public ResponseEntity<String> eliminar(@PathVariable Long id) {
        boolean eliminado = serviceUzyTPlanificacion.eliminar(id);
        if (eliminado) {
            return ResponseEntity.ok("El registro se eliminĂ³ exitosamente.");
        } else {
            return ResponseEntity.notFound().build();
        }
    }
}