using Bogus;
using Knoks.Api.Client.Invoker;
using Knoks.Core;
using System.Collections.Generic;
using System.Linq;

namespace Knoks.Test.Integrations.Api.Tools
{
    public static partial class ApiMocker
    {
        public const string PassPhoneEnd = "123456", PassPinCode = "1234";

        public static readonly Dictionary<string, string[]> PhonePrefixFormats = new Dictionary<string, string[]>
        {
            ["IL"] = new[] { "+972(054)#" },
            ["RU"] = new[] { "+7-926-#" },
            ["GB"] = new[] { "+44-1689-" },
            ["US"] = new[] { "+19135" },
            ["DE"] = new[] { "+491573#" },
        };

        public static readonly Dictionary<string, PhoneNumber[]> PassPhoneNumbers =
        @"[
            {""OriginalFormat"":""(054)6123456"",""NationalFormat"":""054-612-3456"",""E164Format"":""+972546123456"",""CountryCode2"":""IL""},
            {""OriginalFormat"":""+972(054)0123456"",""NationalFormat"":""054-012-3456"",""E164Format"":""+972540123456"",""CountryCode2"":""IL""},
            {""OriginalFormat"":""+7-926-3123456"",""NationalFormat"":""8 (926) 312-34-56"",""E164Format"":""+79263123456"",""CountryCode2"":""RU""},
            {""OriginalFormat"":""8(900)312-34-56"",""NationalFormat"":""8 (900) 312-34-56"",""E164Format"":""+79003123456"",""CountryCode2"":""RU""},
            {""OriginalFormat"":""+44-1689-123456"",""NationalFormat"":""01689 123456"",""E164Format"":""+441689123456"",""CountryCode2"":""GB""},
            {""OriginalFormat"":""(913) 512-3456"",""NationalFormat"":""(913) 512-3456"",""E164Format"":""+19135123456"",""CountryCode2"":""US""},
            {""OriginalFormat"":""+19135123456"",""NationalFormat"":""(913) 512-3456"",""E164Format"":""+19135123456"",""CountryCode2"":""US""},
            {""OriginalFormat"":""01573 6123456"",""NationalFormat"":""01573 6123456"",""E164Format"":""+4915736123456"",""CountryCode2"":""DE""},
            {""OriginalFormat"":""+4915736123456"",""NationalFormat"":""01573 6123456"",""E164Format"":""+4915736123456"",""CountryCode2"":""DE""}
        ]".JsonTo<IList<PhoneNumber>>().GroupBy(o => o.CountryCode2).ToDictionary(g => g.Key, g => g.ToArray());

        public static string FakePhone(bool isTest, string countryCode)
        {
            var phoneNumber = Faker.PickRandom(PhonePrefixFormats[countryCode]) + (isTest ? PassPhoneEnd : "######");
            return Faker.Random.Replace(phoneNumber);
        }

        public static PhoneNumber FakePhoneNumber(string countryCode)
        {
            return Faker.PickRandom(PassPhoneNumbers[countryCode]);
        }
    }
}
