package com.platform2easy.genesis.domain.service;

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

import java.util.List;

@Service
@AllArgsConstructor
public class CompanyService {

    private final CompanyRepository repository;

    @Transactional
    public Company salvar(Company company) {
        repository.save(company);
        return company;
    }

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

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

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