package kr.co.hanwha.hifive.network.hanwha;

import java.net.SocketTimeoutException;

import okhttp3.Response;

/**
 * Created by sanghoonkwon on 2018. 1. 11..
 */

public class HanwhaNetworkError {
    public static final int CODE_SUCCESS = 200;
    public static final int CODE_404_NOT_FOUND_ERROR = 404;
    public static final int CODE_DEFAULT = 9000;
    public static final int CODE_EXCEPTION = 9001;
    public static final int CODE_CONNECT_TIMED_OUT = 9002;

    public static final int CODE_NETWORK_CONNECTION_ERROR = 9003;

    int statusCode;
    String message;
    Response response;

    public HanwhaNetworkError() {
        this.statusCode = CODE_DEFAULT;
        this.message = "";
    }

    public HanwhaNetworkError(int statusCode) {
        this.statusCode = statusCode;
        this.message = "";
    }

    public HanwhaNetworkError(String message) {
        this.statusCode = CODE_DEFAULT;
        this.message = message;
    }


    public HanwhaNetworkError(Exception e) {
        if (e instanceof SocketTimeoutException) {
            this.statusCode = CODE_CONNECT_TIMED_OUT;
            this.message = e.getMessage();
        } else {
            this.statusCode = CODE_EXCEPTION;
            this.message = e.getMessage();
        }
    }

    public HanwhaNetworkError(int statusCode, String message) {
        this.statusCode = statusCode;
        this.message = message;
    }

    public HanwhaNetworkError(int statusCode, String message, Response response) {
        this.statusCode = statusCode;
        this.message = message;
        this.response = response;
    }

    public HanwhaNetworkError(int statusCode, Exception e) {
        this.statusCode = statusCode;
        this.message = e.getMessage();
    }

    public int getStatusCode() {
        return statusCode;
    }

    public String getMessage() {
        return message;
    }

    public Response getResponse() {
        return response;
    }


    public boolean checkCode(int code, int check) {
        return (code == check);
    }

    @Override
    public String toString() {
        return "HanwhaNetworkError{" +
                "statusCode=" + statusCode +
                ", message='" + message + '\'' +
                ", response=" + response +
                '}';
    }
}
