package com.ningdatech.carapi.sys.utils;

import cn.hutool.core.collection.CollUtil;
import com.ningdatech.carapi.car.vehicle.model.NdVehicleBaseInfo;
import com.ningdatech.carapi.datascope.model.DataScopeDto;
import com.ningdatech.carapi.sys.entity.vo.RegionTreeCompanyVO;

import java.util.Optional;

/**
 * @Classname DataScopeCacheFilterUtil
 * @Description
 * @Date 2022/11/21 16:48
 * @Created by PoffyZhang
 */
public class DataScopeCacheFilterUtil {

    public static boolean dataScopeFilter(NdVehicleBaseInfo v, Optional<DataScopeDto> dataScope) {
        if(!dataScope.isPresent()){
            return Boolean.TRUE;
        }

        if(CollUtil.isNotEmpty(dataScope.get().getRegionIds())){
            if(dataScope.get().getRegionIds().contains(v.getRegionId())){
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }else if(CollUtil.isNotEmpty(dataScope.get().getCompanyIds())){
            if(dataScope.get().getCompanyIds().contains(v.getId())){
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    public static boolean dataScopeFilter(RegionTreeCompanyVO v, Optional<DataScopeDto> dataScope) {
        if(!dataScope.isPresent()){
            return Boolean.TRUE;
        }

        if(CollUtil.isNotEmpty(dataScope.get().getRegionIds())){
            if(dataScope.get().getRegionIds().contains(v.getRegionId())){
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }else if(CollUtil.isNotEmpty(dataScope.get().getCompanyIds())){
            if(dataScope.get().getCompanyIds().contains(v.getId())){
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }
}
