package com.gic.haoban.manage.web.utils;

import com.gic.haoban.manage.api.service.StaffApiService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @Author guojx
 * @Date 2023/1/17 10:59
 */
@Component
public class StoreAuthUtils {
    private static final Logger log = LoggerFactory.getLogger(StoreAuthUtils.class);

    @Autowired
    private StaffApiService staffApiService;

    /**
     * 查询区经角色下管辖的门店权限
     * @param clerkId
     * @param wxEnterpriseId
     * @return
     */
    public List<String> queryClerkStoreIds(String clerkId, String wxEnterpriseId){
        List<String> storeIds = staffApiService.getHaoBanStoreIdsRolesByClerkId(clerkId, wxEnterpriseId);
        if (CollectionUtils.isEmpty(storeIds)){
            log.info("根据区经id查询管辖的门店为空 {} {}", clerkId, wxEnterpriseId);
            return Collections.singletonList("-100");
        }
        if (storeIds.size() == 1 && StringUtils.equals(storeIds.get(0), "-1")){
            // 全部门店权限
            log.info("区经有全部门店权限 {}", clerkId);
            return Collections.emptyList();
        }
        return storeIds;
    }
}
