package com.usky.rule.service;

import com.usky.common.core.bean.CommonPage;
import com.usky.rule.domain.RuleEngine;
import com.usky.rule.vo.RuleEngineConfigDTO;
import com.usky.rule.vo.RuleEngineDTO;
import com.usky.rule.vo.RuleEngineDetail;
import com.usky.rule.vo.RuleEnginePageRequest;
import com.usky.rule.vo.action.RuleEngineAction;
import com.usky.rule.vo.constraint.CronConstraint;
import com.usky.rule.vo.constraint.DeviceConstraint;
import com.usky.rule.vo.trigger.CronTrigger;
import com.usky.rule.vo.trigger.DeviceTrigger;
import com.usky.rule.vo.trigger.SpaceTrigger;

import java.util.List;

public interface RuleEngineService {
    void add(RuleEngine ruleEngine);
    void update(RuleEngine ruleEngine);
    void remove(Long id);
    RuleEngine getById(Long id);
    CommonPage<RuleEngine> pageList(RuleEnginePageRequest request);
    /** 查询多条数据（条件同分页，不分页），对应 leo RuleEngineController.list */
    List<RuleEngine> list(RuleEnginePageRequest request);
    void updateStatus(Long id, Integer status);
    List<RuleEngine> listEnabledByProjectId(Long projectId);

    /** 配置规则：保存规则主体 + cron 列表 + 设备绑定（新增或更新） */
    void ruleEngineConfig(RuleEngineDTO dto);

    /** 获取规则完整配置（规则 + cron 列表 + 设备列表） */
    RuleEngineConfigDTO getEngineConfig(Long ruleEngineId);

    /** 手动触发规则：写 rule_engine_log，triggerType=manual，autoTrigger=0 */
    void manualTrigger(Long ruleEngineId);

    /** 定时触发规则：写 rule_engine_log，triggerType=cron，autoTrigger=1（供定时任务调度调用） */
    void triggerByCron(Long ruleEngineId);

    List<CronTrigger> getCronTriggers(List<RuleEngineDetail.CommonVO> commonVOList);

    List<DeviceTrigger> getDeviceTriggers(List<RuleEngineDetail.CommonVO> commonVOList);

    List<SpaceTrigger> getSpaceTriggers(List<RuleEngineDetail.CommonVO> commonVOList);

    List<CronConstraint> getCronConstraints(List<RuleEngineDetail.CommonVO> commonVOList);

    List<DeviceConstraint> getDeviceConstraints(List<RuleEngineDetail.CommonVO> commonVOList);

    List<RuleEngineAction> getActions(List<RuleEngineDetail.CommonVO> commonVOList);

    String getName(Long ruleEngineId);

    String getDetail(Long ruleEngineId);
}
