package com.cool.store.dao;

import com.cool.store.constants.CommonConstants;
import com.cool.store.entity.EnterpriseUserRoleDO;
import com.cool.store.entity.SysRoleDO;
import com.cool.store.enums.DataSourceEnum;
import com.cool.store.mapper.EnterpriseUserRoleMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @date 2023-05-19 02:59
 */
@Repository
public class EnterpriseUserRoleDAO {

    @Resource
    private EnterpriseUserRoleMapper enterpriseUserRoleMapper;

    public Integer batchInsertOrUpdate(List<EnterpriseUserRoleDO> recordList){
        if(CollectionUtils.isEmpty(recordList)){
            return null;
        }
        return enterpriseUserRoleMapper.batchInsertOrUpdate(recordList);
    }

    public Integer deleteRoleInUser(String roleId, DataSourceEnum dataSourceEnum, List<String> excludeUserIds){
        if(StringUtils.isBlank(roleId) || Objects.isNull(dataSourceEnum) || CollectionUtils.isEmpty(excludeUserIds)){
            return null;
        }
        return enterpriseUserRoleMapper.deleteRoleInUser(roleId, dataSourceEnum.getCode(), excludeUserIds);
    }

    public Integer deleteUserInRole(String userId, DataSourceEnum dataSourceEnum, String excludeRoleId){
        if(StringUtils.isAnyBlank(userId, excludeRoleId) || Objects.isNull(dataSourceEnum)){
            return null;
        }
        return enterpriseUserRoleMapper.deleteUserInRole(userId, dataSourceEnum.getCode(), excludeRoleId);
    }

    public Integer deleteUserRole(String userId){
        if(StringUtils.isBlank(userId)){
            return CommonConstants.ZERO;
        }
        return enterpriseUserRoleMapper.deleteUserRole(userId);
    }

}