package cn.axzo.workflow.server.controller.web;

import cn.axzo.karma.client.feign.FlowSupportApi;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.conf.SupportRefreshProperties;
import com.google.common.collect.Lists;
import org.springframework.context.ApplicationContext;

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

import static cn.axzo.workflow.server.controller.delegate.AbstractBpmnTaskAssigneeSelector.populateNameAndAvatar;

/**
 * 公共的获取 BpmnTask
 *
 * @author wangli
 * @since 2024-09-09 16:51
 */
public abstract class BasicPopulateAvatarController {

    @Resource
    protected FlowSupportApi flowSupportApi;
    @Resource
    private SupportRefreshProperties refreshProperties;
    @Resource
    private ApplicationContext applicationContext;

    /**
     * 为一个人填充头像
     *
     * @param assigner
     */
    protected final void populateUsersAvatar(BpmnTaskDelegateAssigner assigner) {
        if (Objects.isNull(assigner)) {
            return;
        }
        populateUsersAvatar(Lists.newArrayList(assigner));
    }

    /**
     * 为一个集合的人填充头像
     *
     * @param assigners
     */
    protected final void populateUsersAvatar(List<BpmnTaskDelegateAssigner> assigners) {
        populateNameAndAvatar(assigners, flowSupportApi, refreshProperties, applicationContext);
    }

}
