package tech.easyflow.ai.service.impl;

import org.springframework.stereotype.Service;
import tech.easyflow.ai.entity.Bot;
import tech.easyflow.ai.enums.PublishStatus;
import tech.easyflow.ai.service.BotApprovalStateService;
import tech.easyflow.approval.enums.ApprovalResourceType;

import java.util.Collection;
import java.util.List;

/**
 * 旧 Bot 审批展示状态派生服务实现。
 */
@Service
public class BotApprovalStateServiceImpl implements BotApprovalStateService {

    private final AiResourceApprovalStateServiceImpl approvalStateService;

    /**
     * 创建 Bot 审批展示状态派生服务。
     *
     * @param approvalStateService 通用 AI 资源审批状态服务
     */
    public BotApprovalStateServiceImpl(AiResourceApprovalStateServiceImpl approvalStateService) {
        this.approvalStateService = approvalStateService;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void fillApprovalState(Bot bot) {
        fillApprovalState(bot == null ? List.of() : List.of(bot));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void fillApprovalState(Collection<Bot> bots) {
        approvalStateService.fillApprovalState(
                bots,
                ApprovalResourceType.BOT.getCode(),
                Bot::getCurrentApprovalInstanceId,
                bot -> PublishStatus.from(bot.getPublishStatus()),
                Bot::getPublishedSnapshotJson,
                Bot::setApprovalPending,
                Bot::setCurrentApprovalActionType,
                Bot::setDisplayPublishStatus
        );
    }
}
