package com.atmob.voiceai.helper;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.atmob.app.lib.handler.RxHttpHandler;
import com.atmob.voiceai.R;
import com.atmob.voiceai.utils.ToastUtil;

public class ErrorHelper {

    public static void errorThrowableToast(Throwable throwable, @ToastUtil.Duration int duration) {
        errorThrowableToast(throwable, R.string.net_error_message, duration);
    }

    public static void errorThrowableToast(Throwable throwable, @StringRes int defaultToastTxtId, @ToastUtil.Duration int duration) {
        if (throwable instanceof RxHttpHandler.ServerErrorException) {
            RxHttpHandler.ServerErrorException serverErrorException = (RxHttpHandler.ServerErrorException) throwable;
            int errorResId = getErrorResId(serverErrorException.getCode());
            if (errorResId == -1) {
                ToastUtil.show(serverErrorException.getMsg(), duration);
            } else {
                ToastUtil.show(errorResId, duration);
            }
        } else {
            ToastUtil.show(defaultToastTxtId, duration);
        }
    }


    @StringRes
    public static int getErrorResId(int errorCode) {
        int errorResId = -1;
        switch (errorCode) {

        }
        return errorResId;
    }
}
