package com.jeelowcode.service.system.mapper;

import com.jeelowcode.tool.framework.mybatis.core.mapper.BaseMapperX;
import com.jeelowcode.tool.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jeelowcode.service.system.entity.UserPositionDO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface UserPositionMapper extends BaseMapperX<UserPositionDO> {

    default List<UserPositionDO> selectListByUserId(Long userId) {
        return selectList(UserPositionDO::getUserId, userId);
    }
    default List<UserPositionDO> selectListByUserId(Long userId,Long deptId) {
        return selectList(Wrappers.lambdaUpdate(UserPositionDO.class)
                .eq(UserPositionDO::getUserId, userId)
                .eq(UserPositionDO::getDeptId,deptId));
    }

    default void deleteByUserIdAndDeptId(Long userId, Long deptId) {
        delete(new LambdaQueryWrapperX<UserPositionDO>()
                .eq(UserPositionDO::getUserId, userId)
                .eq(UserPositionDO::getDeptId, deptId));
    }
    default void deleteByUserIdAndPositionId(Long userId, Collection<Long> positionIds) {
        delete(new LambdaQueryWrapperX<UserPositionDO>()
                .eq(UserPositionDO::getUserId, userId)
                .in(UserPositionDO::getPositionId, positionIds));
    }

    default void deleteByUserIdAndPositionId(Long userId, Long deptId,Collection<Long> positionIds) {
        delete(new LambdaQueryWrapperX<UserPositionDO>()
                .eq(UserPositionDO::getUserId, userId)
                .eq(UserPositionDO::getDeptId, deptId)
                .in(UserPositionDO::getPositionId, positionIds));
    }

    default List<UserPositionDO> selectListByPositionIds(Collection<Long> positionIds) {
        return selectList(UserPositionDO::getPositionId, positionIds);
    }

    default void deleteByUserId(Long userId) {
        delete(Wrappers.lambdaUpdate(UserPositionDO.class).eq(UserPositionDO::getUserId, userId));
    }
}
