/*
 * Conversation SDK
 *  Text Event object model
 *
 * Copyright (c) Nexmo Inc. 2017
 */

var Event = require('./event').Event;

// Conversation Client Error
var ConversationClientError = require('../conversationClientError');

var NexmoApiError = ConversationClientError.NexmoApiError;
var NexmoClientError = ConversationClientError.NexmoClientError;

/**
 * A text event
 *
 * @class TextEvent
 */

var TextEvent = function(conversation, params) {
    this.conversation = conversation;
    this.state = {
        seen_by: {},
        delivered_to: {}
    };
    if (params && params.body) {
        if (params.body.timestamp)
            this.timestamp = params.body.timestamp;
    }
    // Map the params
    for (var key in params) {
        this[key] = params[key];
    }
};

TextEvent.prototype = new Event(this.conversation, this);

/**
 * Set the message status to 'seen'
 * @returns {Promise}
 */
TextEvent.prototype.seen = function() {
    this.type = "text";
    return this.seenEvent();
};


/**
 * Set the message status to 'delivered'. 
 * handled by the SDK
 * @returns {Promise}
 */
TextEvent.prototype.delivered = function() {
    this.type = "text";
    return this.deliveredEvent();
};

/**
 * Delete the event
 * @returns {Promise}
 */
TextEvent.prototype.del = function() {
    return this.deleteEvent();
};

module.exports = {
    TextEvent: TextEvent
};