package com.platform2easy.genesis.web.controller;

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

import java.util.List;

@RestController
@RequestMapping("/api/tx_token")
@AllArgsConstructor
public class TxTokenController {

    private final TxTokenService service;

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

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

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

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

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