package com.setqq.script.sdk;

import com.saki.qq.global.ScriptManager;
import com.saki.service.NewService;
import com.setqq.script.Msg;
import com.setqq.script.NullIDException;
import com.setqq.script.Script;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Saki on 2018/6/25.
 */

public class ServerScript extends ScriptAdapter{
    private String url;
    public ServerScript(NewService service,JSONObject script) throws JSONException {
        this.id = script.getString("id");
        this.version = script.getString("version");
        Script s = ScriptManager.getInstance().findScript(id);
        if(s!=null){
            if(!s.version.equals(version)){
                s.type = 2;
                s.update = script.getString("download");
            }
            return;
        }
        this.name = script.getString("name");
        this.author = script.getString("author");
        this.info = script.getString("info");
        String update = script.getString("download");
        this.ui = script.optString("synopsis");
        this.icon = script.optString("icon");
        initScript(service,update);
    }
    @Override
    public void onLoad(NewService context) {

    }

    @Override
    public void onMessageHandler(Msg msg) {

    }

    @Override
    public String onAction(String value) {
        return null;
    }

    @Override
    public void destroy() {

    }

    @Override
    public String getIcon() {
        return this.icon !=null?this.icon.equals("")?null:this.icon:null;
    }

    @Override
    public boolean hasUI() {
        return this.ui != null && !this.ui.equals("");
    }

    @Override
    public void runFunction(String funName,String param){};
}
