package cn.novalon.gym.manage.db.dao;

import cn.novalon.gym.manage.db.entity.UserRoleEntity;
import org.springframework.data.domain.Sort;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public interface UserRoleDao extends R2dbcRepository<UserRoleEntity, Long> {

    Flux<UserRoleEntity> findByUserId(Long userId);

    Flux<UserRoleEntity> findByUserId(Long userId, Sort sort);

    Flux<UserRoleEntity> findByRoleId(Long roleId);

    Flux<UserRoleEntity> findByRoleId(Long roleId, Sort sort);

    Mono<Long> countByUserId(Long userId);

    Mono<Long> countByRoleId(Long roleId);

    @Modifying
    @Query("DELETE FROM user_role WHERE user_id = :userId")
    Mono<Integer> deleteByUserId(Long userId);

    @Modifying
    @Query("DELETE FROM user_role WHERE role_id = :roleId")
    Mono<Integer> deleteByRoleId(Long roleId);
}
