package com.bsis.peuplement.controler;


import com.bsis.peuplement.model.Redevable;
import com.bsis.peuplement.service.RedevableService;
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 java.util.Optional;

@RestController
@RequestMapping("/redevables")
public class RedevableController {
    @Autowired
    private RedevableService redevableService;
    //.....................................................
    // READ
    //.....................................................
    @GetMapping("/all")
    public ResponseEntity<List<Redevable>> getAll () {
        List<Redevable> redevable = redevableService.getAll();
        return new ResponseEntity<>(redevable, HttpStatus.OK);
    }
    //......................................................
    @RequestMapping("/get/{id}")
    public Optional<Redevable> getDossierById(@PathVariable("id") Long id) {
        return redevableService.getById(id);
    }
    //.....................................................
    @RequestMapping("/count")
    public long count() {
        return redevableService.count();
    }

/*
    //......................................................................
    //                    Create
    //......................................................................
    @PostMapping("/add")
    public ResponseEntity<Redevable> addRedevable(@RequestBody Redevable redevable) {
        Redevable newRedevable = redevableService.add(redevable);
        return new ResponseEntity<>(newRedevable, HttpStatus.CREATED);
    }
    //......................................................................
    //                    Read
    //......................................................................
    @RequestMapping("/get/{id}")
    public Optional<Redevable> getRedevableById(@PathVariable("id") String id) {
        return redevableService.getById(id);
    }
    //......................................................................
    @GetMapping("/all")
    public ResponseEntity<List<Redevable>> getAll () {
        List<Redevable> redevables = redevableService.getAll();
        return new ResponseEntity<>(redevables, HttpStatus.OK);
    }
    //......................................................................
    @RequestMapping("/getid/{redevableId}")
    public Redevable getRedevableByRedevableId(@PathVariable("redevableId") String redevableId) {
        return redevableService.getByRedevableId(redevableId);
    }
    //......................................................................
    @RequestMapping("/count")
    public long count() {
        return redevableService.count();
    }
    //......................................................................
    //                 Update
    //......................................................................
    @PutMapping("/update")
    public ResponseEntity<Redevable> update(@RequestBody Redevable redevable) {
        Redevable updateRedevable = redevableService.update(redevable);
        return new ResponseEntity<>(updateRedevable, HttpStatus.OK);
    }
    //......................................................................
    //                 Delete
    //......................................................................
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<?> delete(@PathVariable("id") String id) {
        redevableService.delete(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
    //......................................................................
    @RequestMapping("/deleteAll")
    public ResponseEntity<?> deleteAll() {
        redevableService.deleteAll();
        return new ResponseEntity<>(HttpStatus.OK);
    }
    //......................................................................
    //......................................................................
//    @RequestMapping("/getXYFichierPlat")
//    public String []  getXYFichierPlat(@RequestBody Dossier dossier) {
//        return redevableService.xyFichierPlat(dossier);
//
//    }
*/

}
