package com.kfzs.duanduan.utils.net;

import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.kfzs.duanduan.proto.ApiRequestOuterClass;
import com.kfzs.duanduan.proto.Session;

/**
 * <pre>
 *     sinlov
 *
 *     /\__/\
 *    /`    '\
 *  ≈≈≈ 0  0 ≈≈≈ Hello world!
 *    \  --  /
 *   /        \
 *  /          \
 * |            |
 *  \  ||  ||  /
 *   \_oo__oo_/≡≡≡≡≡≡≡≡o
 *
 * </pre>
 * Created by sinlov on 17/2/28.
 */
public class AuthRequestBytes {

    private static AuthRequestBytes instance;

    public static synchronized AuthRequestBytes getInstance() {
        if (instance == null) {
            instance = new AuthRequestBytes();
        }
        return instance;
    }

    public byte[] buildRegisterBytes(@Nullable String pwd, String account,String invitationCode, String captchaKey, @Nullable String captcha, int step, @Nullable String smsCode) {
        Session.SessionIn.Builder sessionBuild = Session.SessionIn.newBuilder();
        sessionBuild.setStep(step);
        sessionBuild.setAccount(account);
        sessionBuild.setCaptchaKey(captchaKey);
        sessionBuild.setInvitationCode(invitationCode);
        if (!TextUtils.isEmpty(pwd)) {
            sessionBuild.setPwd(pwd);
        }
        if (!TextUtils.isEmpty(captcha)) {
            sessionBuild.setCaptcha(captcha);
        }
        if (!TextUtils.isEmpty(smsCode)) {
            sessionBuild.setSmsSeccode(smsCode);
        }
        Session.SessionIn sessionOut = sessionBuild.build();
        ApiRequestOuterClass.ApiRequest.Builder reqBuild = ApiRequestOuterClass.ApiRequest.newBuilder();
        reqBuild.setSessionIn(sessionOut);
        return reqBuild.build().toByteArray();
    }
}
