import type { DecisionFormState, DecisionResult } from "./types";

export const initialDecisionResults: DecisionResult[] = [
  {
    id: "decision_1",
    name: "3号大棚灌溉决策",
    source: "auto",
    executionMode: "auto",
    triggerCondition: {
      device: "土壤传感器-03",
      parameter: "土壤湿度",
      operator: "<",
      value: "30",
    },
    execution: {
      device: "水肥机-01",
      action: "open",
      duration: 45,
    },
    level: "important",
    confidence: 0.89,
    recommendation: "当土壤湿度低于30%时，自动打开水肥机进行灌溉45分钟",
    explanation:
      "综合分析：\n1. 模型预测土壤湿度为35%，低于开花期最佳湿度(60-70%)\n2. 天气预报未来3天无降雨，蒸发量较大(8.5mm/day)\n3. 当前处于开花期，是需水关键期\n4. 历史记录显示上次灌溉已过3天\n因此建议尽快灌溉，保证作物正常生长",
    actionItems: [
      "系统检测到土壤湿度低于30%",
      "自动启动水肥机-01",
      "持续灌溉45分钟",
      "灌溉结束后系统自动关闭",
      "记录灌溉时间和用水量",
    ],
    inputData: {
      models: [
        { id: "output_3", name: "灌溉需求预测模型" },
        { id: "output_1", name: "番茄生长预测模型" },
      ],
      rules: [
        { id: "rule_2", name: "开花期灌溉规则" },
        { id: "rule_5", name: "干旱预警规则" },
      ],
      context: [
        { id: "ctx_4", name: "天气预报" },
        { id: "ctx_5", name: "历史灌溉记录" },
      ],
    },
    fusionProcess: [
      {
        step: "模型输出分析",
        result: "灌溉需求预测: 120升，置信度 0.91",
        weight: 0.6,
      },
      {
        step: "业务规则匹配",
        result: "匹配到“开花期灌溉规则”，权重 0.9",
        weight: 0.5,
      },
      {
        step: "上下文验证",
        result: "天气晴朗无雨，土壤湿度35%，符合灌溉条件",
        weight: 0.45,
      },
      {
        step: "加权融合计算",
        result: "综合置信度 0.89（超过阈值 0.75）",
        weight: 1,
      },
      {
        step: "决策生成",
        result: "生成可执行灌溉方案",
        weight: 1,
      },
    ],
    generatedAt: "2024-10-23 10:35:00",
  },
  {
    id: "decision_2",
    name: "2号大棚温度控制决策",
    source: "manual",
    executionMode: "manual",
    triggerCondition: {
      device: "温度传感器-02",
      parameter: "空气温度",
      operator: ">",
      value: "35",
    },
    execution: {
      device: "排风扇-02",
      action: "open",
      duration: 20,
    },
    level: "normal",
    confidence: 0.86,
    recommendation: "当大棚温度高于35℃时，手动打开排风扇20分钟进行降温",
    explanation: "根据现场观察，2号大棚在高温天气容易超过35℃，影响作物生长。建议当温度传感器检测到超过35℃时，及时打开排风扇降温。",
    actionItems: [
      "监测温度传感器-02的实时数据",
      "温度超过35℃时收到系统提醒",
      "点击执行按钮，启动排风扇-02",
      "持续运行20分钟后自动关闭",
      "记录降温效果",
    ],
    inputData: {
      models: [],
      rules: [],
      context: [],
    },
    fusionProcess: [],
    generatedAt: "2024-10-22 14:20:00",
    createdBy: "张三",
  },
  {
    id: "decision_3",
    name: "1号大棚湿度调节决策",
    source: "auto",
    executionMode: "auto",
    triggerCondition: {
      device: "湿度传感器-01",
      parameter: "空气湿度",
      operator: "<",
      value: "60",
    },
    execution: {
      device: "喷雾器-01",
      action: "open",
      duration: 15,
    },
    level: "suggestion",
    confidence: 0.92,
    recommendation: "当空气湿度低于60%时，自动打开喷雾器15分钟增加湿度",
    explanation:
      "综合分析：\n1. 番茄生长最佳湿度为60-80%\n2. 当前处于开花期，湿度过低会影响授粉\n3. 设置自动触发条件，保持适宜湿度\n因此建议当湿度低于60%时自动喷雾加湿",
    actionItems: [
      "系统检测到空气湿度低于60%",
      "自动启动喷雾器-01",
      "持续喷雾15分钟",
      "喷雾结束后系统自动关闭",
      "记录湿度变化曲线",
    ],
    inputData: {
      models: [{ id: "output_1", name: "番茄生长预测模型" }],
      rules: [{ id: "rule_3", name: "开花期湿度规则" }],
      context: [
        { id: "ctx_1", name: "地块信息" },
        { id: "ctx_2", name: "作物品种" },
      ],
    },
    fusionProcess: [
      {
        step: "模型输出分析",
        result: "最佳湿度范围：60-80%",
        weight: 0.7,
      },
      {
        step: "业务规则匹配",
        result: "匹配到“开花期湿度规则”",
        weight: 0.55,
      },
      {
        step: "上下文验证",
        result: "当前处于开花期，湿度控制至关重要",
        weight: 0.4,
      },
      {
        step: "加权融合计算",
        result: "综合置信度 0.92",
        weight: 1,
      },
      {
        step: "决策生成",
        result: "生成自动湿度控制方案",
        weight: 1,
      },
    ],
    generatedAt: "2024-10-23 09:15:00",
  },
];

export const createDefaultDecisionFormState = (): DecisionFormState => ({
  name: "",
  level: "normal",
  confidence: 80,
  executionMode: "manual",
  triggerDevice: "",
  triggerParameter: "",
  triggerOperator: "<",
  triggerValue: "",
  targetDevice: "",
  targetAction: "open",
  duration: 30,
  recommendation: "",
  explanation: "",
  actionItems: "",
});
