package com.platform2easy.genesis.web.controller;

import com.platform2easy.genesis.domain.model.Wallet;
import com.platform2easy.genesis.domain.service.WalletService;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/wallet")
@AllArgsConstructor
public class WalletController {

    private final WalletService service;

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    public List<Wallet> listAll() {
        return service.listarTodos();
    }

    @GetMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    public Wallet getById(@PathVariable Long id) {
        return service.buscarPorId(id);
    }

    @GetMapping("/company/{companyId}")
    @ResponseStatus(HttpStatus.OK)
    public Wallet getWalletByCompanyId(@PathVariable Integer companyId) {
        return service.buscarPorEmpresa(companyId);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Wallet create(@RequestBody Wallet wallet) {
        wallet.setId(null);
        return service.salvar(wallet);
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    public Wallet update(@PathVariable Long id, @RequestBody Wallet wallet) {
        wallet.setId(id);
        return service.salvar(wallet);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable Long id) {
        service.deletarPorId(id);
    }
}
