package com.kfzs.duanduan.data.graph.provider.user;

// @formatter:off
import com.kfzs.duanduan.data.graph.provider.base.BaseModel;

import java.util.Date;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * A user info which is part of a team.
 */
@SuppressWarnings({"WeakerAccess", "unused", "ConstantConditions"})
public class UserBean implements UserModel {
    private long mId;
    private int mUid;
    private String mUserName;
    private long mUpdateTime;
    private String mPhone;
    private String mNickname;
    private String mUserIcon;
    private String mAvatar;
    private String mOpenId;
    private String mMail;
    private String mRefreshToken;

    /**
     * Primary key.
     */
    @Override
    public long getId() {
        return mId;
    }

    /**
     * Primary key.
     */
    public void setId(long id) {
        mId = id;
    }

    /**
     * uid at user of this user.
     */
    @Override
    public int getUid() {
        return mUid;
    }

    /**
     * uid at user of this user.
     */
    public void setUid(int uid) {
        mUid = uid;
    }

    /**
     * user_name of this user.
     * Cannot be {@code null}.
     */
    @NonNull
    @Override
    public String getUserName() {
        return mUserName;
    }

    /**
     * user_name of this user.
     * Must not be {@code null}.
     */
    public void setUserName(@NonNull String userName) {
        if (userName == null) throw new IllegalArgumentException("userName must not be null");
        mUserName = userName;
    }

    /**
     * update time of this user.
     */
    @Override
    public long getUpdateTime() {
        return mUpdateTime;
    }

    /**
     * update time of this user.
     */
    public void setUpdateTime(long updateTime) {
        mUpdateTime = updateTime;
    }

    /**
     * phone of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getPhone() {
        return mPhone;
    }

    /**
     * phone of this user.
     * Can be {@code null}.
     */
    public void setPhone(@Nullable String phone) {
        mPhone = phone;
    }

    /**
     * nickname of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getNickname() {
        return mNickname;
    }

    /**
     * nickname of this user.
     * Can be {@code null}.
     */
    public void setNickname(@Nullable String nickname) {
        mNickname = nickname;
    }

    /**
     * user_icon of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getUserIcon() {
        return mUserIcon;
    }

    /**
     * user_icon of this user.
     * Can be {@code null}.
     */
    public void setUserIcon(@Nullable String userIcon) {
        mUserIcon = userIcon;
    }

    /**
     * avatar of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getAvatar() {
        return mAvatar;
    }

    /**
     * avatar of this user.
     * Can be {@code null}.
     */
    public void setAvatar(@Nullable String avatar) {
        mAvatar = avatar;
    }

    /**
     * open_id of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getOpenId() {
        return mOpenId;
    }

    /**
     * open_id of this user.
     * Can be {@code null}.
     */
    public void setOpenId(@Nullable String openId) {
        mOpenId = openId;
    }

    /**
     * mail of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getMail() {
        return mMail;
    }

    /**
     * mail of this user.
     * Can be {@code null}.
     */
    public void setMail(@Nullable String mail) {
        mMail = mail;
    }

    /**
     * refresh_token of this user.
     * Can be {@code null}.
     */
    @Nullable
    @Override
    public String getRefreshToken() {
        return mRefreshToken;
    }

    /**
     * refresh_token of this user.
     * Can be {@code null}.
     */
    public void setRefreshToken(@Nullable String refreshToken) {
        mRefreshToken = refreshToken;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserBean bean = (UserBean) o;
        return mId == bean.mId;
    }

    @Override
    public int hashCode() {
        return (int) (mId ^ (mId >>> 32));
    }

    /**
     * Instantiate a new User with specified values.
     */
    @NonNull
    public static UserBean newInstance(long id, int uid, @NonNull String userName, long updateTime, @Nullable String phone, @Nullable String nickname, @Nullable String userIcon, @Nullable String avatar, @Nullable String openId, @Nullable String mail, @Nullable String refreshToken) {
        if (userName == null) throw new IllegalArgumentException("userName must not be null");
        UserBean res = new UserBean();
        res.mId = id;
        res.mUid = uid;
        res.mUserName = userName;
        res.mUpdateTime = updateTime;
        res.mPhone = phone;
        res.mNickname = nickname;
        res.mUserIcon = userIcon;
        res.mAvatar = avatar;
        res.mOpenId = openId;
        res.mMail = mail;
        res.mRefreshToken = refreshToken;
        return res;
    }

    /**
     * Instantiate a new User with all the values copied from the given model.
     */
    @NonNull
    public static UserBean copy(@NonNull UserModel from) {
        UserBean res = new UserBean();
        res.mId = from.getId();
        res.mUid = from.getUid();
        res.mUserName = from.getUserName();
        res.mUpdateTime = from.getUpdateTime();
        res.mPhone = from.getPhone();
        res.mNickname = from.getNickname();
        res.mUserIcon = from.getUserIcon();
        res.mAvatar = from.getAvatar();
        res.mOpenId = from.getOpenId();
        res.mMail = from.getMail();
        res.mRefreshToken = from.getRefreshToken();
        return res;
    }

    public static class Builder {
        private UserBean mRes = new UserBean();

        /**
         * Primary key.
         */
        public Builder id(long id) {
            mRes.mId = id;
            return this;
        }

        /**
         * uid at user of this user.
         */
        public Builder uid(int uid) {
            mRes.mUid = uid;
            return this;
        }

        /**
         * user_name of this user.
         * Must not be {@code null}.
         */
        public Builder userName(@NonNull String userName) {
            if (userName == null) throw new IllegalArgumentException("userName must not be null");
            mRes.mUserName = userName;
            return this;
        }

        /**
         * update time of this user.
         */
        public Builder updateTime(long updateTime) {
            mRes.mUpdateTime = updateTime;
            return this;
        }

        /**
         * phone of this user.
         * Can be {@code null}.
         */
        public Builder phone(@Nullable String phone) {
            mRes.mPhone = phone;
            return this;
        }

        /**
         * nickname of this user.
         * Can be {@code null}.
         */
        public Builder nickname(@Nullable String nickname) {
            mRes.mNickname = nickname;
            return this;
        }

        /**
         * user_icon of this user.
         * Can be {@code null}.
         */
        public Builder userIcon(@Nullable String userIcon) {
            mRes.mUserIcon = userIcon;
            return this;
        }

        /**
         * avatar of this user.
         * Can be {@code null}.
         */
        public Builder avatar(@Nullable String avatar) {
            mRes.mAvatar = avatar;
            return this;
        }

        /**
         * open_id of this user.
         * Can be {@code null}.
         */
        public Builder openId(@Nullable String openId) {
            mRes.mOpenId = openId;
            return this;
        }

        /**
         * mail of this user.
         * Can be {@code null}.
         */
        public Builder mail(@Nullable String mail) {
            mRes.mMail = mail;
            return this;
        }

        /**
         * refresh_token of this user.
         * Can be {@code null}.
         */
        public Builder refreshToken(@Nullable String refreshToken) {
            mRes.mRefreshToken = refreshToken;
            return this;
        }

        /**
         * Get a new User built with the given values.
         */
        public UserBean build() {
            if (mRes.mUserName == null) throw new IllegalArgumentException("userName must not be null");
            return mRes;
        }
    }

    public static Builder newBuilder() {
        return new Builder();
    }
}
