package com.dacrt.SBIABackend.repository;

import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.dacrt.SBIABackend.entity.Operationlines;
import com.dacrt.SBIABackend.entity.Processes;
import com.dacrt.SBIABackend.entity.Serviceoffers;
import com.dacrt.SBIABackend.entity.Strategies;
@Repository
public interface ServiceoffersRepository extends JpaRepository<Serviceoffers,Integer>,JpaSpecificationExecutor<Serviceoffers>{
	boolean existsById(Integer id);
	
	Optional<Serviceoffers> findById(int id);
	
    boolean existsByName(String name);
	
	Optional<Serviceoffers> getByName(String name);
	
	@Transactional
	@Modifying
	@Query(" DELETE FROM Processserviceoffers e where e.serviceofferid.id = ?1 ")
	void deleteProcessserviceoffersbyid(Integer id);
	
	@Transactional
	@Modifying
	@Query(value=" UPDATE main.channels SET serviceoffers = ?2 where id = ?1 ", nativeQuery = true)
	void updateChannelsOffersbyid(Integer id, String ofertas);
	
	@Transactional
	@Modifying
	@Query(value=" UPDATE main.applications SET serviceoffers = ?2 where id = ?1 ", nativeQuery = true)
	void updateApplicationOffersbyid(Integer id, String ofertas);
	
	@Query(" SELECT count(e) FROM Processserviceoffers e where e.serviceofferid.id = ?1 ")
	int cantProcessserviceoffersbyid(Integer id);
	
	@Query(" SELECT count(e) FROM Serviceoffers e where e.offer_full=1 ")
	int cantOfferFull();
	
}