package com.kfzs.duanduan.utils.net;

import com.android.volleyplus.Response;
import com.kfzs.duanduan.bll.UrlBll;
import com.kfzs.duanduan.proto.ApiResponseOuterClass;
import com.kfzs.duanduan.proto.Captcha;

/**
 * <pre>
 *     sinlov
 *
 *     /\__/\
 *    /`    '\
 *  ≈≈≈ 0  0 ≈≈≈ Hello world!
 *    \  --  /
 *   /        \
 *  /          \
 * |            |
 *  \  ||  ||  /
 *   \_oo__oo_/≡≡≡≡≡≡≡≡o
 *
 * </pre>
 * Created by sinlov on 17/2/28.
 */
public abstract class ResponseAuthCaptcha implements Response.Listener<ApiResponseOuterClass.ApiResponse> {
    @Override
    public void onResponse(ApiResponseOuterClass.ApiResponse apiResponse) {
        int code = apiResponse.getCodeValue();
        if (code == ApiResponseOuterClass.Codes.Success_VALUE) {
            Captcha.CaptchaOut captchaOut = apiResponse.getCaptchaOut();
            if (null != captchaOut) {
                String key = captchaOut.getKey();
                onAuthCaptchaURL(key, UrlBll.AuthApi.SHOW_CAPTCHA + key);
            } else {
                onErrorAuthCaptchaURL(code, "parse error getCaptchaOut is Empty!");
            }
        } else {
            onErrorAuthCaptchaURL(code, apiResponse.getMsg());
        }
    }

    public abstract void onAuthCaptchaURL(String key, String url);

    public abstract void onErrorAuthCaptchaURL(int code, String msg);
}
