using System;
using System.Data.SqlClient;
using System.Linq;
using SvetoforVKBot.Models.Updates;
using VkNet;
using VkNet.Enums.SafetyEnums;
using VkNet.Model.Keyboard;
using VkNet.Model.RequestParams;

namespace SvetoforVKBot.Models.Commands.LK.Reports
{
    public class SelectCreateReportCommand : Command
    {
        public override string Name => "{\"button\":\"selectCreateReport\"}";

        public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
        {
        }

        public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
        {
            var chatId = update.@object.message.from_id;
            MessagesSendParams @params = new MessagesSendParams();
            var keyboardBuilder = new KeyboardBuilder().Clear();

            try
            {
                var user = db.Users.Single(usr => usr.chatId == chatId);              

                @params.Message = "✏Отчёт за " + DateTime.Now.ToShortDateString() + "\n\n" +
                    user.firstName + ", как Вы себя чувствуете?";


                keyboardBuilder
                    .AddButton("😀", "selectReportRate-10", KeyboardButtonColor.Primary)
                    .AddButton("😐", "selectReportRate-5", KeyboardButtonColor.Primary)
                    .AddButton("🙁", "selectReportRate-1", KeyboardButtonColor.Primary)
                    .AddLine()
                    .AddButton("Назад", "startPL", KeyboardButtonColor.Default);

                @params.Keyboard = keyboardBuilder.Build();
                @params.UserId = chatId;
                @params.RandomId = GetRandomId();
                client.Messages.SendAsync(@params);

            }
            catch (Exception ee)
            {
                @params.Message = "Ошибка в SelectCreateReportCommand: " + ee.Message;
                @params.Attachments = null;
                @params.Keyboard = null;
                @params.UserId = 59111081;
                @params.RandomId = GetRandomId();
                client.Messages.SendAsync(@params);
            }
        }
    }
}