package tw.com.altob.goodpk.Loader;

import android.content.Context;

import com.ga.sdk.api.ApiResult;
import com.ga.sdk.loader.AbstractApiLoaderCallback;
import com.orhanobut.logger.Logger;

import org.json.JSONException;

import tw.com.altob.goodpk.Parser.BaseApiParser;
import tw.com.altob.goodpk.Util.PrefsUtil;

public abstract class ApiLoaderCallback<T> extends AbstractApiLoaderCallback<T> {

    @Override
    protected String toErrorMessage(ApiResult apiResult) {

        String message;
        try {
            message = BaseApiParser.getMessage(apiResult.getError().getBody());
        } catch (JSONException e) {
            int status = apiResult.getError().getStatus();
            String reason = apiResult.getError().getReason();

            message = "[" + status + "] " + reason;
        }

        return message;
    }

    @Override
    protected void handleForbidden(Context context) {
        try {
            PrefsUtil.clearData(context);
            //DBUtil.cleanData(context);
        } catch (Exception e) {
            Logger.e(e, e.getMessage());
        }
    }


}