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


import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavZonaDetalle;
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavZonaDetalle.IServiceUzyTavZonaDetalle;
import org.springframework.beans.factory.annotation.Autowired;
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 + "/zonadetalle")

public class UzyTavZonaDetalleController {

    private final IServiceUzyTavZonaDetalle serviceUzyTavZonaDetalle;

    @Autowired
    public UzyTavZonaDetalleController(IServiceUzyTavZonaDetalle serviceUzyTavZonaDetalle) {
        this.serviceUzyTavZonaDetalle = serviceUzyTavZonaDetalle;
    }

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

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

    @GetMapping("/registrosRelacionadosConPrograma/{programaId}")
    public ResponseEntity<List<DtoUzyTavZonaDetalle>> ListarRegistrosRelacionadosConPrograma(@PathVariable Long programaId) {
        return new ResponseEntity<>(serviceUzyTavZonaDetalle.ListarRegistrosRelacionadosConPrograma(programaId), HttpStatus.OK);
    }



    @GetMapping("/registrosRelacionadosConProyecto/{proyecID}")
    public ResponseEntity<List<DtoUzyTavZonaDetalle>> ListarRegistrosRelacionadosConProyec(@PathVariable Long proyecID) {
        return new ResponseEntity<>(serviceUzyTavZonaDetalle.ListarRegistrosRelacionadosConProyec(proyecID), HttpStatus.OK);
    }


    @PostMapping("/guardar")
    public ResponseEntity<DtoUzyTavZonaDetalle> guardar(@RequestBody DtoUzyTavZonaDetalle dtoUzyTavZonaDetalle) {
        DtoUzyTavZonaDetalle savedDto = serviceUzyTavZonaDetalle.guardar(dtoUzyTavZonaDetalle);
        return ResponseEntity.ok(savedDto);
    }

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

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

}