/*
 * 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;
//@param用于描述一个方法或函数的参数，它通常在方法的注释中使用。@param后面跟着参数的名称和描述
//@return是一种Java文档标记，用于指定方法或函数的返回值类型及其含义。(在Java文档中，它通常用于描述方法的预期结果，包括返回值类型、异常处理和错误情况等

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;
    /**
     * 表示GTask中的一个节点，是其他具体节点的父类
     */
    public abstract class Node {

        private String mGid = null; // GTask的gid
        private String mName = ""; // 节点名称
        private long mLastModified = 0; // 上次修改时间
        private boolean mDeleted = false; // 是否已删除

        /**
         * 获取用于创建节点的JSON对象
         * @param actionId 操作ID
         * @return 用于创建节点的JSON对象
         */
        public abstract JSONObject getCreateAction(int actionId);

        /**
         * 获取用于更新节点的JSON对象
         * @param actionId 操作ID
         * @return 用于更新节点的JSON对象
         */
        public abstract JSONObject getUpdateAction(int actionId);

        /**
         * 根据从远程JSON对象中获取的信息设置节点的内容
         * @param js 从远程JSON对象中获取的信息
         */
        public abstract void setContentByRemoteJSON(JSONObject js);

        /**
         * 根据从本地JSON对象中获取的信息设置节点的内容
         * @param js 从本地JSON对象中获取的信息
         */
        public abstract void setContentByLocalJSON(JSONObject js);

        /**
         * 获取用于保存到本地的JSON对象
         * @return 用于保存到本地的JSON对象
         */
        public abstract JSONObject getLocalJSONFromContent();

        /**
         * 根据数据库游标获取同步操作
         * @param c 数据库游标
         * @return 同步操作
         */
        public abstract int getSyncAction(Cursor c);

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

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

        /**
         * 设置上次修改时间
         * @param lastModified 上次修改时间
         */
        public void setLastModified(long lastModified) {
            this.mLastModified = lastModified;
        }

        /**
         * 设置节点是否已删除
         * @param deleted 节点是否已删除
         */
        public void setDeleted(boolean deleted) {
            this.mDeleted = deleted;
        }

        /**
         * 获取GTask的gid
         * @return GTask的gid
         */
        public String getGid() {
            return this.mGid;
        }

        /**
         * 获取节点名称
         * @return 节点名称
         */
        public String getName() {
            return this.mName;
        }

        /**
         * 获取上次修改时间
         * @return 上次修改时间
         */
        public long getLastModified() {
            return this.mLastModified;
        }

        /**
         * 获取节点是否已删除
         * @return 节点是否已删除
         */
        public boolean getDeleted() {
            return this.mDeleted;
        }
    }