package br.gov.sigefp.rh.api;

import br.gov.sigefp.rh.domain.AgentBankAccount;
import br.gov.sigefp.rh.repository.AgentBankAccountRepository;
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/bank-accounts")
@RequiredArgsConstructor
public class AgentBankAccountController {

    private final AgentBankAccountRepository repository;
    private final br.gov.sigefp.rh.service.AgentBankAccountService service;

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

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

    @PostMapping
    public AgentBankAccount save(@RequestBody AgentBankAccount account) {
        return service.save(account);
    }

    @PutMapping("/{id}")
    public AgentBankAccount update(@PathVariable("id") UUID id, @RequestBody AgentBankAccount account) {
        account.setId(id);
        return service.update(account);
    }

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