package br.gov.sigefp.rh.api;

import br.gov.sigefp.rh.domain.AgentContract;
import br.gov.sigefp.rh.repository.AgentContractRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/api/rh/contracts")
@RequiredArgsConstructor
public class AgentContractController {

    private final AgentContractRepository repository;
    private final br.gov.sigefp.rh.service.AgentContractService contractService;

    @GetMapping
    public List<AgentContract> findAll() {
        return repository.findAll();
    }

    @GetMapping("/agent/{agentId}")
    public List<AgentContract> findByAgent(@PathVariable("agentId") UUID agentId) {
        return repository.findByAgentId(agentId);
    }

    @PostMapping
    public AgentContract save(@RequestBody AgentContract contract) {
        return contractService.saveContract(contract);
    }

    @PutMapping("/{id}")
    public AgentContract update(@PathVariable("id") UUID id, @RequestBody AgentContract contract) {
        contract.setId(id);
        return contractService.updateContract(contract);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") UUID id) {
        repository.deleteById(id);
        return ResponseEntity.ok().build();
    }
}
