package com.bam.relationshipcorelibrary.Core.DatabaseObjects.Message;

import org.joda.time.DateTime;

import java.io.Serializable;

/**
 * Created by bahram on 28.06.2015.
 */
public class ConversationMessage implements Serializable
{
    // The ID of this specific message
    private long messageDB_ID;

    // The conversation ID that this individual message belongs to
    private long conversation_ID;

    // The UUID of the RelPerson that sent the message
    private String senderDB_ID;

    // The actual message String
    private String message;

    // The timestamp for when the sender sent the message
    private DateTime messageTimestamp;

    // The type of message
    private MessageType messageType;

    // Boolean indicating if the message was delivered to GCM (not to user, but GCM).
    private boolean messageSent;

    // Boolean indicating if the message was delivered to Conversation.
    private boolean messageDelivered;


    public static final String MESSAGE_TABLE_NAME = "ConversationMessage";
    public static final String MESSAGE_ID_FIELD = "Message_ID";
    public static final String MESSAGE_CONVERSATION_ID_FIELD = "Conversation_ID";
    public static final String MESSAGE_SENDERDB_ID_FIELD = "SenderDB_ID";
    public static final String MESSAGE_MESSAGE_FIELD = "Message";
    public static final String MESSAGE_MESSAGETIMESTAMP_FIELD = "MessageTimestamp";
    public static final String MESSAGE_MESSAGETYPE_FIELD = "MessageType";
    public static final String MESSAGE_MESSAGESENT_FIELD = "MessageSent";
    public static final String MESSAGE_MESSAGEDELIVERED_FIELD = "MessageDelivered";


    public ConversationMessage(long messageDB_ID, long conversation_ID, String senderDB_ID,
                               String message, DateTime messageTimestamp, MessageType messageType)
    {
        this.messageDB_ID = messageDB_ID;
        this.conversation_ID = conversation_ID;
        this.senderDB_ID = senderDB_ID;
        this.message = message;
        this.messageTimestamp = messageTimestamp;
        this.messageType = messageType;

        messageSent = false;
        messageDelivered = false;
    }


    public ConversationMessage(long conversation_ID, String senderDB_ID,
                               String message, DateTime messageTimestamp, MessageType messageType)
    {
        this.conversation_ID = conversation_ID;
        this.senderDB_ID = senderDB_ID;
        this.message = message;
        this.messageTimestamp = messageTimestamp;
        this.messageType = messageType;

        messageSent = false;
        messageDelivered = false;
    }


    /*****************
     * GETTERS
     *****************/

    /**
     * Get the ID of this specific message.
     */
    public long getMessageDB_ID()
    {
        return messageDB_ID;
    }

    /**
     * Get the conversation ID that this individual message belongs to.
     */
    public long getConversation_ID()
    {
        return conversation_ID;
    }

    /**
     * Get the UUID of the RelPerson that sent the message.
     */
    public String getSenderDB_ID()
    {
        return senderDB_ID;
    }

    /**
     * Get the actual message String.
     */
    public String getMessage()
    {
        return message;
    }

    /**
     * Get the timestamp for when the sender sent the message.
     */
    public DateTime getMessageTimestamp()
    {
        return messageTimestamp;
    }

    /**
     * Get the type of message.
     */
    public MessageType getMessageType()
    {
        return messageType;
    }

    /**
     * Get boolean indicating if the message was delivered to GCM (not to user, but GCM).
     */
    public boolean isMessageDelivered()
    {
        return messageDelivered;
    }

    public int isMessageDeliveredInt()
    {
        if( messageDelivered )
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    /**
     * Get boolean indicating if the message was delivered to Conversation.
     */
    public boolean isMessageSent()
    {
        return messageSent;
    }

    public int isMessageSentInt()
    {
        if( messageSent )
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }


    /*****************
     * SETTERS
     *****************/

    /**
     * Set the ID of this specific message.
     */
    public void setMessageDB_ID(long messageDB_ID)
    {
        this.messageDB_ID = messageDB_ID;
    }

    /**
     * Set the conversation ID that this individual message belongs to.
     */
    public void setConversation_ID(long conversation_ID)
    {
        this.conversation_ID = conversation_ID;
    }

    /**
     * Set the UUID of the RelPerson that sent the message.
     */
    public void setSenderDB_ID(String senderDB_ID)
    {
        this.senderDB_ID = senderDB_ID;
    }

    /**
     * Set the actual message String.
     */
    public void setMessage(String message)
    {
        this.message = message;
    }

    /**
     * Set the timestamp for when the sender sent the message.
     */
    public void setMessageTimestamp(DateTime messageTimestamp)
    {
        this.messageTimestamp = messageTimestamp;
    }

    /**
     * Set the type of message.
     */
    public void setMessageType(MessageType messageType)
    {
        this.messageType = messageType;
    }

    /**
     * Set boolean indicating if the message was delivered to GCM (not to user, but GCM).
     */
    public void setMessageSent(boolean messageSent)
    {
        this.messageSent = messageSent;
    }

    public void setMessageSentInt(int messageSent)
    {
        if( messageSent > 0 )
        {
            this.messageSent = true;
        }
        else
        {
            this.messageSent = false;
        }
    }

    /**
     * Set boolean indicating if the message was delivered to Conversation.
     */
    public void setMessageDelivered(boolean messageDelivered)
    {
        this.messageDelivered = messageDelivered;
    }

    public void setMessageDeliveredInt(int messageDelivered)
    {
        if( messageDelivered > 0 )
        {
            this.messageDelivered = true;
        }
        else
        {
            this.messageDelivered = false;
        }
    }

    /**
     * A enum that will represent the type of this message.
     */
    public enum MessageType
    {
        TEXT, IMAGE, LOCATION
    }
}
