package com.dacrt.SBIABackend.security.repository;

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

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


import com.dacrt.SBIABackend.security.entity.Menu;
import com.dacrt.SBIABackend.security.dto.AccessDto;
import com.dacrt.SBIABackend.security.entity.Users;
import com.dacrt.SBIABackend.security.entity.Access;

@Repository
public interface MenuRepository  extends JpaRepository<Menu,Integer>{
	
	@Query(value=" SELECT * FROM main.menu m WHERE m.father = 0 or m.father IS NULL",nativeQuery=true)
	List<Menu> getByAllFather();
	
	@Query(value=" SELECT * FROM main.menu a WHERE a.id = ?1",nativeQuery=true)
	Optional<Menu> findByFather(Integer father);
	
	@Query(value=" SELECT * FROM main.menu a WHERE a.content = ?1",nativeQuery=true)
	Optional<Menu> findByContent(String content);
	
	@Query(value=" SELECT count(a.father) FROM main.menu a WHERE a.content = ?1",nativeQuery=true)
	int findByContentCount(String content);
	
	@Query(value=" SELECT a.dsc FROM main.menu a WHERE a.id = ?1 LIMIT 1",nativeQuery=true)
	String findByDscPadre(Integer father);
	
	@Query(value=" SELECT a.content FROM main.menu a WHERE a.dsc = ?1 and a.id= ?2 LIMIT 1",nativeQuery=true)
	String findByContentDesc(String father,Integer id);
	
	@Query(value=" SELECT count(1) FROM main.rolesprivileges a WHERE a.rolid = ?1 and a.privilegeid = ?2 ",nativeQuery=true)
	//List<Audit> getAllMovAudit(int orderIn,int asc);
	int getCantbyRolAndPriviMenu(int rolid,int privilegeid);
	
	
}
