package shop.alien.job.store;

import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import shop.alien.entity.result.R;
import shop.alien.job.feign.AlienStoreFeign;

/**
 * 评论申诉-用户补充 AI 分析定时任务（通过 Feign 调用 alien-store）
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class StoreCommentAppealSupplementJob {

    private final AlienStoreFeign alienStoreFeign;

    @XxlJob("getStoreCommentAppealSupplementAppealJob")
    public R<String> getStoreCommentAppealSupplementAppealJob() {
        log.info("【定时任务】用户补充申诉-提交AI分析：开始执行");
        try {
            R<String> result = alienStoreFeign.submitStoreCommentAppealSupplementAnalyze();
            log.info("【定时任务】用户补充申诉-提交AI分析：执行完成，result={}", result);
            return result != null ? result : R.fail("调用 alien-store 返回为空");
        } catch (Exception e) {
            log.error("【定时任务】用户补充申诉-提交AI分析：执行异常", e);
            throw e;
        }
    }

    @XxlJob("getStoreCommentAppealSupplementCompletedResult")
    public R<String> getStoreCommentAppealSupplementCompletedResult() {
        log.info("【定时任务】用户补充申诉-轮询AI结果：开始执行");
        try {
            R<String> result = alienStoreFeign.pollStoreCommentAppealSupplementCompletedResult();
            log.info("【定时任务】用户补充申诉-轮询AI结果：执行完成，result={}", result);
            return result != null ? result : R.fail("调用 alien-store 返回为空");
        } catch (Exception e) {
            log.error("【定时任务】用户补充申诉-轮询AI结果：执行异常", e);
            throw e;
        }
    }
}
