package com.platform2easy.genesis.web.controller;

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

import java.util.List;

@RestController
@RequestMapping("/api/token")
@AllArgsConstructor
public class TokenController {

    private final TokenService service;

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

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

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

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

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