package io.gmss.fiscad.controllers.infocad.metier;


import io.gmss.fiscad.interfaces.infocad.metier.PersonneService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.dto.PersonneCompletDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "api/personne", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')")
public class PersonneController {

    private final PersonneService personneService;

    @GetMapping("/get-details/{id}")
    public ResponseEntity<?> getDetails(@PathVariable Long id)   {
        try{
            PersonneCompletDTO personneCompletDTO = personneService.getPersonneComplete(id);
            return new ResponseEntity<>(
                    new ApiResponse<>(true, personneCompletDTO, "Personne retrouvée avec  succès."),
                    HttpStatus.OK
            );
        }catch (Exception e){
            return new ResponseEntity<>(
                    new ApiResponse<>(false, e.getMessage()),
                    HttpStatus.OK
            );
        }
    }
}
