package com.quansu.heifengwuliu.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.quansu.heifengwuliu.config.ConfigMMKV;
import com.ysnows.base.inter.IModel;
import com.ysnows.base.inter.IUser;
import com.ysnows.base.utils.MMKVManager;

import org.jetbrains.annotations.Nullable;

public class User implements IUser, Parcelable, IModel {


    public String uid;
    public String name;
    public String mobile;
    public String avatar;
    public String money;
    public int type;//1是司机 2是货主
    public String status;
    public String openid;
    public String union_id;
    public String create_time;
    public String update_time;
    public String delete_time;

    public Boolean isDriver() {
        return type == 1;
    }

    public Boolean isShipper() {
        return type == 2;
    }

    @Nullable
    @Override
    public String avatar() {
        return avatar;
    }

    public User() {
    }


    @Nullable
    public static User get() {
        return MMKVManager.instance().decodeParcelable(ConfigMMKV.USER, User.class);
    }

    @Override
    public boolean save() {
        return MMKVManager.instance().encode(ConfigMMKV.USER, this);
    }

    public static boolean isLogin() {
        return get() != null;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.uid);
        dest.writeString(this.name);
        dest.writeString(this.mobile);
        dest.writeString(this.avatar);
        dest.writeString(this.money);
        dest.writeInt(this.type);
        dest.writeString(this.status);
        dest.writeString(this.openid);
        dest.writeString(this.union_id);
        dest.writeString(this.create_time);
        dest.writeString(this.update_time);
        dest.writeString(this.delete_time);
    }

    protected User(Parcel in) {
        this.uid = in.readString();
        this.name = in.readString();
        this.mobile = in.readString();
        this.avatar = in.readString();
        this.money = in.readString();
        this.type = in.readInt();
        this.status = in.readString();
        this.openid = in.readString();
        this.union_id = in.readString();
        this.create_time = in.readString();
        this.update_time = in.readString();
        this.delete_time = in.readString();
    }

    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel source) {
            return new User(source);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };
}
