package com.platform2easy.genesis.web.controller;

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

import java.util.List;

@RestController
@RequestMapping("/api/tx_coin")
@AllArgsConstructor
public class TxCoinController {

    private final TxCoinService service;

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

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

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public TxCoin create(@RequestBody TxCoin txCoin) {
        return service.salvar(txCoin);
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    public TxCoin update(@PathVariable String id, @RequestBody TxCoin txCoin) {
        txCoin.setId(id);
        return service.salvar(txCoin);
    }

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