package com.renttracker.renttrackeriknsa.Repository;

import com.renttracker.renttrackeriknsa.Entity.Bien;
import com.renttracker.renttrackeriknsa.Entity.Role;
import com.renttracker.renttrackeriknsa.Entity.UserBienRoles;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserBienRoleRepository extends JpaRepository<UserBienRoles, Long> {
    int findByRole(int role);

    @Query(value="select DISTINCT * from user_bien_roles ubr where ubr.user = ?1", nativeQuery = true)
    List<UserBienRoles> getRent(Long userId);

    @Query(value="select DISTINCT * from user_bien_roles ubr where ubr.user = ?1 and role = 2", nativeQuery = true)
    List<UserBienRoles> getLocataire(Long userId);

    @Query(value="select DISTINCT * from user_bien_roles ubr where ubr.bien = ?1 and ubr.role = ?2", nativeQuery = true)
    UserBienRoles EstLoue(Bien bien, Role role);

    @Query(value="select DISTINCT * from user_bien_roles where role = ?1", nativeQuery = true)
    List<UserBienRoles> getBien(int role);

}