using PatrickChatCtrlTemplate.Portable.Models;
using PatrickChatCtrlTemplate.Portable.ViewModels;
using Telerik.XamarinForms.ConversationalUI;

namespace PatrickChatCtrlTemplate.Portable.Converters
{
    public class SimpleChatItemConverter : IChatItemConverter
    {
        public ChatItem ConvertToChatItem(object dataItem, ChatItemConverterContext context)
        {
            SimpleChatItem item = (SimpleChatItem)dataItem;

            TextMessage textMessage = new TextMessage
            {
                Data = dataItem,
                Author = item.Author,
                Text = item.Text
            };

            return textMessage;
        }
        public object ConvertToDataItem(object message, ChatItemConverterContext context)
        {
            MainPageViewModel vm = (MainPageViewModel)context.Chat.BindingContext;

            return new SimpleChatItem { Author = vm.Me, Text = (string)message, };
        }
    }
}
