/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */
package com.fq.channel.sdk.base.interfaces;

import java.util.Map;

public class PluginResult {

	private final Status mStatus;
	private final int mMessageType;
	private String mMessage;
	private Object mRawMessage;

	public PluginResult(Status status) {
		this(status, StatusMessages[status.ordinal()]);
	}

	public PluginResult(Status status, String message) {
		mStatus = status;
		mMessageType = message == null ? MESSAGE_TYPE_NULL
				: MESSAGE_TYPE_STRING;

		mMessage = message;
		mRawMessage = message;
	}


	public PluginResult(Status status, Object message) {
		mStatus = status;
		mMessageType = message == null ? MESSAGE_TYPE_NULL
				: MESSAGE_TYPE_OBJECT;

		mMessage = message != null ? message.toString() : null;
		mRawMessage = message;
	}

	public PluginResult(Status status, Map<String, Object> message) {
		mStatus = status;
		mMessageType = message == null ? MESSAGE_TYPE_NULL
				: MESSAGE_TYPE_MAP;

		mMessage = message != null ? message.toString() : null;
		mRawMessage = message;
	}
	
	
	public PluginResult(Status status, int i) {
		mStatus = status;
		mMessageType = MESSAGE_TYPE_NUMBER;

		mMessage = String.valueOf(i);
		mRawMessage = i;
	}

	public PluginResult(Status status, float f) {
		mStatus = status;
		mMessageType = MESSAGE_TYPE_NUMBER;

		mMessage = String.valueOf(f);
		mRawMessage = f;
	}

	public PluginResult(Status status, boolean b) {
		mStatus = status;
		mMessageType = MESSAGE_TYPE_BOOLEAN;

		mMessage = String.valueOf(b);
		mRawMessage = b;
	}

	public Status getStatus() {
		return mStatus;
	}

	public int getMessageType() {
		return mMessageType;
	}

	public String getMessage() {
		return mMessage;
	}

	public Object getRawMessage() {
		return mRawMessage;
	}


	public static final int MESSAGE_TYPE_STRING = 1;
	public static final int MESSAGE_TYPE_JSON_OBJECT = 2;
	public static final int MESSAGE_TYPE_JSON_ARRAY = 3;
	public static final int MESSAGE_TYPE_NUMBER = 4;
	public static final int MESSAGE_TYPE_BOOLEAN = 5;
	public static final int MESSAGE_TYPE_NULL = 6;
	public static final int MESSAGE_TYPE_MAP = 7;
	public static final int MESSAGE_TYPE_OBJECT = 8;

	private static String[] StatusMessages = new String[] { "OK", "Error",
			"Cancel", "Wait", "Shift" };

	public static enum Status {

		OK(0), ERROR(1), CANCEL(2), WAIT(3), SHIFT(4), TOKEN_EXIPRED(5);

		Status(int state) {
		}

	}
}
