package com.pavis.admin.aigc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.pavis.admin.aigc.mapper.AgentPlanStepMapper;
import com.pavis.admin.aigc.model.entity.AgentPlanStepDO;
import com.pavis.admin.aigc.model.query.AgentPlanStepQuery;
import com.pavis.admin.aigc.model.req.AgentPlanStepReq;
import com.pavis.admin.aigc.model.resp.AgentPlanStepDetailResp;
import com.pavis.admin.aigc.model.resp.AgentPlanStepResp;
import com.pavis.admin.aigc.service.AgentPlanStepService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import top.continew.starter.extension.crud.service.BaseServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * 智能体规划步骤记录业务实现
 *
 * @author semi
 * @since 2025/05/29 12:50
 */
@Service
@RequiredArgsConstructor
public class AgentPlanStepServiceImpl extends BaseServiceImpl<AgentPlanStepMapper, AgentPlanStepDO, AgentPlanStepResp, AgentPlanStepDetailResp, AgentPlanStepQuery, AgentPlanStepReq> implements AgentPlanStepService {
    @Override
    public boolean saveOrUpdateBatch(List<AgentPlanStepResp> respList) {
        List<AgentPlanStepDO> planStepDOList = new ArrayList<>();
        for (AgentPlanStepResp planStepResp : respList) {
            AgentPlanStepDO planStepDO = new AgentPlanStepDO();
            BeanUtil.copyProperties(planStepResp, planStepDO);
            planStepDOList.add(planStepDO);
        }
        List<BatchResult> batchResults = baseMapper.insertOrUpdate(planStepDOList);
        return !batchResults.isEmpty();
    }

    @Override
    public List<AgentPlanStepResp> getByPlanId(Long planId) {
        return baseMapper.selectByPlanId(planId);
    }
}