package com.platform2easy.genesis.domain.service;

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

import java.util.List;

@Service
@AllArgsConstructor
public class CprService {

    private final CprRepository repository;

    @Transactional
    public Cpr salvar(Cpr cpr) {
        repository.save(cpr);
        return cpr;
    }

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

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

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