package com.platform2easy.genesis.domain.service;

import com.platform2easy.genesis.domain.model.Token;
import com.platform2easy.genesis.domain.repository.TokenRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@AllArgsConstructor
public class TokenService {

    private final TokenRepository repository;

    @Transactional
    public Token salvar(Token token) {
        repository.save(token);
        return token;
    }

    public List<Token> listarTodos() {
        return repository.findAll();
    }

    public Token buscarPorId(Long id) {
        return repository.findById(id).orElseThrow();
    }

    public void deletarPorId(Long id) {
        repository.deleteById(id);
    }
}
