package ec.edu.espe.movilidad.MovilidadWS.Controller;
import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTCanton;
import ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTProvincia;
import ec.edu.espe.movilidad.MovilidadWS.Service.UzyTCanton.IServiceUzyTCanton;

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 + "/canton")

public class UzyTCantonController {

    private final IServiceUzyTCanton serviceUzyTCanton;

    @Autowired
    public UzyTCantonController(IServiceUzyTCanton serviceUzyTCanton) {
        this.serviceUzyTCanton = serviceUzyTCanton;
    }

    @GetMapping("/exampleFindId/{id}")
    public ResponseEntity<DtoUzyTCanton> ListarPorID(@PathVariable String id) {
        return new ResponseEntity<>(serviceUzyTCanton.ListarPorID(id), HttpStatus.OK);
    }

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




    @GetMapping("/datosRealacionadosConProvincia/{id}")
    public List<DtoUzyTCanton> findByIdDatosConParaEvaTipo1(@PathVariable("id") String id) {
        return serviceUzyTCanton.findByIdDatosConProvincia(id);
    }

    @GetMapping("/{uzytcanton_id}")
    public ResponseEntity<DtoUzyTProvincia> getCantonByParroquiaId(@PathVariable String uzytcanton_id) {
        return new ResponseEntity<>(serviceUzyTCanton.findCantonByCantonId(uzytcanton_id), HttpStatus.OK);
    }

    @PostMapping("/guardar")
    public ResponseEntity<DtoUzyTCanton> guardar(@RequestBody DtoUzyTCanton dtoUzyTCanton) {
        return new ResponseEntity<>(serviceUzyTCanton.guardar(dtoUzyTCanton), HttpStatus.OK);
    }

    @PutMapping("/editar/{id}")
    public ResponseEntity<DtoUzyTCanton> editar(@PathVariable String id,
                                                @RequestBody DtoUzyTCanton dtoUzyTCanton) {
        return new ResponseEntity<>(serviceUzyTCanton.editar(id, dtoUzyTCanton), HttpStatus.OK);
    }

    @DeleteMapping("/eliminar/{id}")
    public ResponseEntity<Void> eliminar(@PathVariable String id) {
        serviceUzyTCanton.eliminar(id);
        return ResponseEntity.ok().build();
    }

}