/*
 * 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;

//下面是一些同步实时操作的基础数据类型，定义了指示相关操作的常量。
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;
        mName = "";
        mLastModified = 0;
        mDeleted = false;
    }

    //根据操作ID获取用于创建节点的 JSON 对象。
    public abstract JSONObject getCreateAction(int actionId);

    //根据操作ID获取用于更新节点的 JSON 对象。
    public abstract JSONObject getUpdateAction(int actionId);

    //根据云端JSON数据设置节点的内容。
    public abstract void setContentByRemoteJSON(JSONObject js);

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

    //根据节点的内容生成本地 JSON 对象。
    public abstract JSONObject getLocalJSONFromContent();

    //根据游标获取同步操作类型。
    public abstract int getSyncAction(Cursor c);

    //用于记录用于标识节点的ID
    public void setGid(String gid) {
        this.mGid = gid;
    }

    //用于记录节点名称
    public void setName(String name) {
        this.mName = name;
    }
 
    //用于记录节点最后的修改时间
    public void setLastModified(long lastModified) {
        this.mLastModified = lastModified;
    }

    //用于表示节点是否删除
    public void setDeleted(boolean deleted) {
        this.mDeleted = deleted;
    }

    //返回用于标识节点的ID
    public String getGid() {
        return this.mGid;
    }

    //用于返回节点名称
    public String getName() {
        return this.mName;
    }

    //返回节点最后的修改时间
    public long getLastModified() {
        return this.mLastModified;
    }

    //判断节点是否删除
    public boolean getDeleted() {
        return this.mDeleted;
    }

}
