package com.gic.haoban.manage.web.controller.content.adaptor;

import com.gic.haoban.manage.api.dto.role.StoreRoleDTO;
import com.gic.haoban.manage.api.service.StaffApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @Author MUSI
 * @Date 2023/3/25 10:29 PM
 * @Description
 * @Version
 **/
@Slf4j
@Component
public class ClerkStoreAdaptor {

    @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;
    }

    /**
     * 获取超管管理门店的总数
     * @param clerkId
     * @param wxEnterpriseId
     * @return
     */
    public Integer countAdminManagerStore(String clerkId, String wxEnterpriseId) {
        StoreRoleDTO storeRole = staffApiService.getCountHaoBanStoreIdsByClerkId(clerkId, wxEnterpriseId);
        if (storeRole == null) {
            return 0;
        }
        return storeRole.getStoreCount();
    }

}
