/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.dubbo.rpc.cluster.router;

import java.util.Map;

/**
 * TODO Extract more code here if necessary
 */
public abstract class AbstractRouterRule {
    private String rawRule;
    private boolean runtime = true;
    private boolean force = false;
    private boolean valid = true;
    private boolean enabled = true;
    private int priority;
    private boolean dynamic = false;

    private String scope;
    private String key;

    protected void parseFromMap0(Map<String, Object> map) {
        setRawRule((String) map.get("rawRule"));

        Object runtime = map.get("runtime");
        if (runtime != null) {
            setRuntime(Boolean.parseBoolean(runtime.toString()));
        }

        Object force = map.get("force");
        if (force != null) {
            setForce(Boolean.parseBoolean(force.toString()));
        }

        Object valid = map.get("valid");
        if (valid != null) {
            setValid(Boolean.parseBoolean(valid.toString()));
        }

        Object enabled = map.get("enabled");
        if (enabled != null) {
            setEnabled(Boolean.parseBoolean(enabled.toString()));
        }

        Object priority = map.get("priority");
        if (priority != null) {
            setPriority(Integer.parseInt(priority.toString()));
        }

        Object dynamic = map.get("dynamic");
        if (dynamic != null) {
            setDynamic(Boolean.parseBoolean(dynamic.toString()));
        }

        setScope((String) map.get("scope"));
        setKey((String) map.get("key"));
    }

    public String getRawRule() {
        return rawRule;
    }

    public void setRawRule(String rawRule) {
        this.rawRule = rawRule;
    }

    public boolean isRuntime() {
        return runtime;
    }

    public void setRuntime(boolean runtime) {
        this.runtime = runtime;
    }

    public boolean isForce() {
        return force;
    }

    public void setForce(boolean force) {
        this.force = force;
    }

    public boolean isValid() {
        return valid;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public boolean isDynamic() {
        return dynamic;
    }

    public void setDynamic(boolean dynamic) {
        this.dynamic = dynamic;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}
