﻿using JhinBot.Enums;
using JhinBot.Interface;
using JhinBot.GlobalConst;
using System.Collections.Generic;
using JhinBot.Convo.Validators;
using JhinBot.DiscordObjects;
using JhinBot.Validators.Implementation;
using JhinBot.Services;

namespace JhinBot.Providers
{
    public class ConvoValidatorProvider
    {
        private readonly IHelpService _helpService;

        private static readonly Dictionary<StepType, string> stepErrorMessages = new Dictionary<StepType, string>()
        {
            { StepType.Name, $"The name must be longer than 0 characters and contain less than {Global.Params.MAX_NAME_LENGTH} characters!" },
            { StepType.Text, $"The text entered was over {Global.Params.MAX_CHAR_PER_MESSAGE} characters! Try again with a shorter text." },
            { StepType.Date, "The date you entered was incorrect! Try checking the format or making sure it's not in the past." },
            { StepType.TimeZone, "The timezone you entered wasn't found! Try with another similar to yours.\n" +
                                    $"If you think it should be included in the list, contact **{Owner.OwnerInstance.ToString()}**." },
            { StepType.Duration, "The duration you entered was incorrect! Try checking the format or making sure it's not negative." },
            { StepType.ListChoice, "The {0} you are trying to modify couldn't be found!" },
            { StepType.Confirm, "Confirmation did not succeed! Nothing from this will be saved!" }
        };

        public ConvoValidatorProvider(IHelpService helpService)
        {
            _helpService = helpService;
        }

        public IValidator GetTypedValidator(StepType stepType, ConversationType type, GuildConfig guildConfig = null)
        {
            var errorMsg = stepErrorMessages[stepType];
            switch (stepType)
            {
                case StepType.Text:
                    return new BodyValidator(errorMsg);
                case StepType.Date:
                    return new DateValidator(errorMsg);
                case StepType.Duration:
                    return new DurationValidator(errorMsg);
                case StepType.ListChoice:
                    return new ListChoiceValidator(guildConfig, errorMsg, type);
                case StepType.Name:
                    return new NameValidator(guildConfig, errorMsg, _helpService, type);
                case StepType.TimeZone:
                    return new TimeZoneValidator(errorMsg);
                case StepType.Confirm:
                    return new ConfirmValidator(errorMsg);
                default:
                    return null;
            }
        }
    }
}
