package com.cool.store.dao.store;

import cn.hutool.core.collection.CollStreamUtil;
import com.cool.store.entity.store.StoreMasterSignerInfoDO;
import com.cool.store.mapper.store.StoreMasterSignerInfoMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 门店签约信息DAO
 * </p>
 *
 * @author wangff
 * @since 2025/9/23
 */
@Repository
@RequiredArgsConstructor
public class StoreMasterSignerInfoDAO {
    private final StoreMasterSignerInfoMapper storeMasterSignerInfoMapper;

    /**
     * 获取门店签约信息Map
     */
    public Map<String, StoreMasterSignerInfoDO> getSignerMapByStoreIds(List<String> storeIds) {
        if (CollectionUtils.isEmpty(storeIds)) {
            return Collections.emptyMap();
        }
        List<StoreMasterSignerInfoDO> list = storeMasterSignerInfoMapper.selectByStoreIds(storeIds);
        return CollStreamUtil.toMap(list, StoreMasterSignerInfoDO::getStoreId, v -> v);
    }

    /**
     * 根据门店id查询
     */
    public StoreMasterSignerInfoDO getByStoreId(String storeId) {
        return storeMasterSignerInfoMapper.selectOne(StoreMasterSignerInfoDO.builder().storeId(storeId).build());
    }

    public List<StoreMasterSignerInfoDO> getListByIdCard(Collection<String> idCards) {
        if (CollectionUtils.isEmpty(idCards)) {
            return Collections.emptyList();
        }
        Example example = new Example(StoreMasterSignerInfoDO.class);
        example.createCriteria()
                .orIn("signer1IdCardNo", idCards)
                .orIn("signer2IdCardNo", idCards);
        return storeMasterSignerInfoMapper.selectByExample(example);
    }
}
