package com.platform2easy.genesis.domain.service.cerc;

import com.platform2easy.genesis.domain.model.cerc.SolicitacaoRegistroCpr;
import com.platform2easy.genesis.domain.model.cerc.StatusSolicitacaoRegistroCpr;
import com.platform2easy.genesis.domain.repository.cerc.SolicitacaoRegistroCprRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@AllArgsConstructor
public class SolicitacaoRegistroCprService {

    private final SolicitacaoRegistroCprRepository repository;

    @Transactional
    public void save(SolicitacaoRegistroCpr entity) {
        if (entity.getId() == null) entity.setStatus(StatusSolicitacaoRegistroCpr.NOVO);

        repository.save(entity);
    }

    public SolicitacaoRegistroCpr getById(Long id) {
        return repository.findById(id).orElse(new SolicitacaoRegistroCpr());
    }

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

    public List<SolicitacaoRegistroCpr> listAll() {
        return repository.findAll();
    }
}
