package com.platform2easy.genesis.domain.service;

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

import java.util.List;

@Service
@AllArgsConstructor
public class OrderbookService {

    private final OrderbookRepository repository;

    @Transactional
    public Orderbook salvar(Orderbook orderbook) {
        repository.save(orderbook);
        return orderbook;
    }

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

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

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

    public List<Orderbook> listarPorIsToken(Boolean isToken) {
        return repository.findByIsToken(isToken);
    }
}