/*
 * 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;//引用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;//long类型 表明最后一次的修改的时间

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

    /**
     *.构造函数，进行初始化，界面没有，名字为空，最后一次修改时间为0（没有修改），表征是否删除。
     */
    public Node() {
        mGid = null;
        mName = "";
        mLastModified = 0;
        mDeleted = false;
    }

    public abstract JSONObject getCreateAction(int actionId);

    public abstract JSONObject getUpdateAction(int actionId);

    public abstract void setContentByRemoteJSON(JSONObject js);

    public abstract void setContentByLocalJSON(JSONObject js);

    public abstract JSONObject getLocalJSONFromContent();

    public abstract int getSyncAction(Cursor c);

    /**
     * 设置 gid
     * @param gid
     */
    public void setGid(String gid) {
        this.mGid = gid;
    }

    /**
     * 设置名称
     * @param name
     */
    public void setName(String name) {
        this.mName = name;
    }

    public void setLastModified(long lastModified) {
        this.mLastModified = lastModified;
    }

    public void setDeleted(boolean deleted) {
        this.mDeleted = deleted;
    }

    public String getGid() {
        return this.mGid;
    }

    public String getName() {
        return this.mName;
    }

    /**
     * 获取最近创建时间标识
     * @return
     */
    public long getLastModified() {
        return this.mLastModified;
    }

    /**
     * 获取删除标识
     * @return
     */
    public boolean getDeleted() {
        return this.mDeleted;
    }

}
