/*
 * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
 *
 * Licensed 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 net.micode.notes.gtask.data;

import android.database.Cursor;

import org.json.JSONObject;

/**
 * 应该是同步操作的基础数据类型，定义了相关指示同步操作的常量
 * 关键字：abstract
 */
public abstract class Node {
    //定义了各种用于表征同步状态的常量
    public static final int SYNC_ACTION_NONE = 0;// 本地和云端都无可更新内容（即本地和云端内容一致）

    public static final int SYNC_ACTION_ADD_REMOTE = 1;// 需要在远程云端增加内容

    public static final int SYNC_ACTION_ADD_LOCAL = 2;// 需要在本地增加内容

    public static final int SYNC_ACTION_DEL_REMOTE = 3;// 需要在远程云端删除内容

    public static final int SYNC_ACTION_DEL_LOCAL = 4;// 需要在本地删除内容

    public static final int SYNC_ACTION_UPDATE_REMOTE = 5;// 需要将本地内容更新到远程云端

    public static final int SYNC_ACTION_UPDATE_LOCAL = 6;// 需要将远程云端内容更新到本地

    public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 同步出现冲突

    public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误

    private String mGid;

    private String mName;

    private long mLastModified;//记录最后一次修改时间

    private boolean mDeleted;//表征是否被删除

    public Node() {
        mGid = null;                        // 初始化 mGid 为 null
        mName = "";                         // 初始化 mName 为空字符串
        mLastModified = 0;                  // 初始化 mLastModified 为 0
        mDeleted = false;                   // 初始化 mDeleted 为 false
    }

    public abstract JSONObject getCreateAction(int actionId);                  // 获取创建节点的操作信息的抽象方法

    public abstract JSONObject getUpdateAction(int actionId);                  // 获取更新节点的操作信息的抽象方法

    public abstract void setContentByRemoteJSON(JSONObject js);               // 根据远程JSON数据设置节点内容的抽象方法

    public abstract void setContentByLocalJSON(JSONObject js);                // 根据本地JSON数据设置节点内容的抽象方法

    public abstract JSONObject getLocalJSONFromContent();                      // 从节点内容中获取本地JSON数据的抽象方法

    public abstract int getSyncAction(Cursor c);                                // 获取同步节点的操作信息的抽象方法

    public void setGid(String gid) {
        this.mGid = gid;                     // 设置 mGid 的取值为传入的 gid
    }

    public void setName(String name) {
        this.mName = name;                   // 设置 mName 的取值为传入的 name
    }

    public void setLastModified(long lastModified) {
        this.mLastModified = lastModified;   // 设置 mLastModified 的取值为传入的 lastModified
    }

    public void setDeleted(boolean deleted) {
        this.mDeleted = deleted;             // 设置 mDeleted 的取值为传入的 deleted
    }

    public String getGid() {
        return this.mGid;                    // 返回 mGid 的取值
    }

    public String getName() {
        return this.mName;                   // 返回 mName 的取值
    }

    public long getLastModified() {
        return this.mLastModified;           // 返回 mLastModified 的取值
    }

    public boolean getDeleted() {
        return this.mDeleted;                // 返回 mDeleted 的取值
    }
}