package com.kfzs.duanduan.datashare.provider.session;

// @formatter:off
import java.util.Date;

import android.content.Context;
import android.content.ContentResolver;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.kfzs.duanduan.datashare.provider.base.AbstractContentValues;

/**
 * Content values wrapper for the {@code session} table.
 */
@SuppressWarnings({"ConstantConditions", "unused"})
public class SessionContentValues extends AbstractContentValues {
    @Override
    public Uri uri() {
        return SessionColumns.CONTENT_URI;
    }

    /**
     * Update row(s) using the values stored by this object and the given selection.
     *
     * @param contentResolver The content resolver to use.
     * @param where The selection to use (can be {@code null}).
     */
    public int update(ContentResolver contentResolver, @Nullable SessionSelection where) {
        return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
    }

    /**
     * Update row(s) using the values stored by this object and the given selection.
     *
     * @param context The context to use.
     * @param where The selection to use (can be {@code null}).
     */
    public int update(Context context, @Nullable SessionSelection where) {
        return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
    }

    /**
     * account of this session. For instance, John.
     */
    public SessionContentValues putAccount(@NonNull String value) {
        if (value == null) throw new IllegalArgumentException("account must not be null");
        mContentValues.put(SessionColumns.ACCOUNT, value);
        return this;
    }


    /**
     * open_id of this session. For instance, John.
     */
    public SessionContentValues putOpenId(@Nullable String value) {
        mContentValues.put(SessionColumns.OPEN_ID, value);
        return this;
    }

    public SessionContentValues putOpenIdNull() {
        mContentValues.putNull(SessionColumns.OPEN_ID);
        return this;
    }

    /**
     * update time of this session.
     */
    public SessionContentValues putUpdateTime(long value) {
        mContentValues.put(SessionColumns.UPDATE_TIME, value);
        return this;
    }


    /**
     * token of this session.
     */
    public SessionContentValues putToken(@Nullable String value) {
        mContentValues.put(SessionColumns.TOKEN, value);
        return this;
    }

    public SessionContentValues putTokenNull() {
        mContentValues.putNull(SessionColumns.TOKEN);
        return this;
    }

    /**
     * uid at user of this session.
     */
    public SessionContentValues putUid(@Nullable Integer value) {
        mContentValues.put(SessionColumns.UID, value);
        return this;
    }

    public SessionContentValues putUidNull() {
        mContentValues.putNull(SessionColumns.UID);
        return this;
    }

    /**
     * data hash save of this session.
     */
    public SessionContentValues putHash(@Nullable Integer value) {
        mContentValues.put(SessionColumns.HASH, value);
        return this;
    }

    public SessionContentValues putHashNull() {
        mContentValues.putNull(SessionColumns.HASH);
        return this;
    }
}
