using SvetoforVKBot.Models.Commands;
using SvetoforVKBot.Models.Commands.Registration;
using SvetoforVKBot.Models.Updates;
using System;
using System.Data.SqlClient;
using System.Security.Cryptography;
using VkNet;
using VkNet.Model.RequestParams;
using System.Text.RegularExpressions;
using SvetoforVKBot.Models.Commands.LK;
using SvetoforVKBot.Models.Commands.LK.Reports;
using SvetoforVKBot.Models.Commands.LK.Consultation;
using SvetoforVKBot.Models.Commands.LK.EditData;
using System.Linq;

namespace SvetoforVKBot.Models.Dop
{
    public class CheckTag
    {
        public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
        {
            var chatId = update.@object.message.from_id;
            MessagesSendParams @params = new MessagesSendParams();
            string tag = "";
            Regex regex = new Regex("[^0-9]");

            try
            {
                tag = db.Users.Single(u => u.chatId == chatId).tag.Trim();
               
                switch (tag)
                {
                    case "Вопрос":
                        GetAskQuestionsCommand getAskQuestions = new GetAskQuestionsCommand();
                        getAskQuestions.Execute(update, client, db);
                        return;

                    case "Подписчик - Регистрация - Пол":
                        GetGenderCommand getGender = new GetGenderCommand();
                        getGender.Execute(update, client, db);
                        return;

                    case "Регистрация - Корпус":
                        GetKorpusCommand getKorpus = new GetKorpusCommand();
                        getKorpus.Execute(update, client, db);
                        return;

                    case "Подписчик - Регистрация - ФИО":
                        GetFIOCommand getFIOCommand = new GetFIOCommand();
                        getFIOCommand.Execute(update, client, db);
                        return;

                    case "Регистрация - Возраст":
                        GetAgeCommand getAgeCommand = new GetAgeCommand();
                        getAgeCommand.Execute(update, client, db);
                        return;

                    case "Личный кабинет - Изменить вес":
                        GetWeightCommand getWeight = new GetWeightCommand();
                        getWeight.Execute(update, client, db);
                        return;

                    case "Личный кабинет - Изменить рост":
                        GetHeightCommand getHeight = new GetHeightCommand();
                        getHeight.Execute(update, client, db);
                        return;

                    case "Подписчик - Регистрация - ДР - Год":
                    case "Личный кабинет - ДР - Год":
                        GetDRYearCommand getDRYear = new GetDRYearCommand();
                        getDRYear.Execute(update, client, db);
                        return;                   

                    case "Подписчик - Регистрация - Телефон":
                        GetPhoneCommand getPhone = new GetPhoneCommand();
                        getPhone.Execute(update, client, db);
                        return;

                    case "Консультация - Вопрос":
                        GetConsultationCommand getConsultation = new GetConsultationCommand();
                        getConsultation.Execute(update, client, db);
                        return;

                    case "Отчет - Комменнт":
                        GetReportCommentCommand getReport = new GetReportCommentCommand();
                        getReport.Execute(update, client, db);
                        return;

                    case "Личный кабинет - ФИО":
                        GetEditFIOCommand getEditFIO = new GetEditFIOCommand();
                        getEditFIO.Execute(update, client, db);
                        return;

                    case "Личный кабинет - Телефон":
                        GetEditPhoneCommand getEditPhone = new GetEditPhoneCommand();
                        getEditPhone.Execute(update, client, db);
                        return;
                }            
            }
            catch (Exception ee)
            {
                @params.Message = "‼Ошибка в CheckTag: " + ee.Message;
                @params.Attachments = null;
                @params.Keyboard = null;
                @params.UserId = 59111081;
                @params.RandomId = GetRandomId();
                client.Messages.SendAsync(@params);
            }
        }

        private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
        private int GetRandomId()
        {

            var intBytes = new byte[4];

            Rng.GetBytes(intBytes);

            return BitConverter.ToInt32(intBytes, 0);
        }
    }
}
