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 int is_info;// 个人认证  1已认证 0未认证
    public int is_car;//车辆认证  1已认证  0未认证
    public int is_company;//公司认证  1已认证 0未认证
    public int is_pay_pwd; //支付密码 1已填写  0未填写
    public int is_pwd; //登录密码 1已填写  0未填写


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

    public Boolean isInfo() {
        return is_info == 1;
    }
    public Boolean isCar() {
        return is_car == 1;
    }
    public Boolean isCompany() {
        return is_company == 1;
    }
    public Boolean isPayPwd() {
        return is_pay_pwd == 1;
    }
    public Boolean isPwd() {
        return is_pwd == 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;
    }

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

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

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

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

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


}
