package com.usky.rule.vo.log;

import com.usky.rule.util.JsonUtil;
import com.usky.rule.vo.log.Content;
import com.usky.rule.vo.log.CronTriggerLog;
import java.util.Map;

public class TriggerCronSerialization implements RuleEngineLogSerialization<CronTriggerLog> {
    public TriggerCronSerialization() {
    }

    public CronTriggerLog serialize(String detail) {
        return (CronTriggerLog)JsonUtil.toObject(detail, CronTriggerLog.class);
    }

    public Content toContent(Object obj) {
        if (obj instanceof Map) {
            CronTriggerLog cronTriggerLog = (CronTriggerLog)JsonUtil.toObject((Map)obj, CronTriggerLog.class);
            return getContent(cronTriggerLog);
        } else if (obj instanceof CronTriggerLog) {
            return getContent((CronTriggerLog)obj);
        } else {
            throw new ClassCastException("TriggerCronSerialization不支持的该类型的转换");
        }
    }

    static Content getContent(CronTriggerLog cronTriggerLog) {
        Content content = new Content();
        content.setTime(cronTriggerLog.getTime());
        content.setContent(cronTriggerLog.getCronExp());
        return content;
    }

    public String getType() {
        return "trigger:cron";
    }
}
