package com.platform2easy.genesis.domain.service;

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

import java.util.List;
import java.util.Optional;

@Service
@AllArgsConstructor
public class WalletService {

    private final WalletRepository repository;

    @Transactional
    public Wallet salvar(Wallet wallet) {
        repository.save(wallet);
        return wallet;
    }

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

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

    public Wallet buscarPorEmpresa(Integer companyId) {
        return repository.findByCompanyId(companyId).orElseThrow();
    }

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