package com.ruoyi.jarvis.domain.dto;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 企微侧多轮交互会话（与 Jarvis_java JDUtil 中 interaction_state + Redis 存 JSON 方式对齐）
 */
public class WeComChatSession {

    public static final String SCENE_JD_LOGISTICS_SHARE = "JD_LOGISTICS_SHARE";
    public static final String STEP_WAIT_REMARK = "WAIT_REMARK";

    private static final DateTimeFormatter FMT = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

    /** 业务场景 */
    private String scene;
    /** 当前步骤 */
    private String step;
    /** 已识别的京东 3.cn 物流短链 */
    private String logisticsUrl;
    /** 最近一次交互时间（超时清理用） */
    private String lastInteractionTime;

    public static WeComChatSession startLogisticsWaitRemark(String logisticsUrl) {
        WeComChatSession s = new WeComChatSession();
        s.setScene(SCENE_JD_LOGISTICS_SHARE);
        s.setStep(STEP_WAIT_REMARK);
        s.setLogisticsUrl(logisticsUrl);
        s.touch();
        return s;
    }

    public void touch() {
        this.lastInteractionTime = LocalDateTime.now().format(FMT);
    }

    /**
     * 是否处于「已收物流链、待备注」步骤。方法名避免使用 isXxx，防止 Fastjson 序列化 Redis JSON 时混入多余布尔字段。
     */
    public boolean matchLogisticsWaitRemark() {
        return SCENE_JD_LOGISTICS_SHARE.equals(scene) && STEP_WAIT_REMARK.equals(step)
                && logisticsUrl != null && !logisticsUrl.isEmpty();
    }

    public String getScene() {
        return scene;
    }

    public void setScene(String scene) {
        this.scene = scene;
    }

    public String getStep() {
        return step;
    }

    public void setStep(String step) {
        this.step = step;
    }

    public String getLogisticsUrl() {
        return logisticsUrl;
    }

    public void setLogisticsUrl(String logisticsUrl) {
        this.logisticsUrl = logisticsUrl;
    }

    public String getLastInteractionTime() {
        return lastInteractionTime;
    }

    public void setLastInteractionTime(String lastInteractionTime) {
        this.lastInteractionTime = lastInteractionTime;
    }
}
