using System.Globalization;

namespace View_by_Distance.Shared.Models.Stateless;

public interface IPersonBirthday
{

    DateTime TestStatic_GetDefaultValue() =>
        GetDefaultValue();

    static DateTime GetDefaultValue() =>
        DateTime.MinValue; // {{1}}SingletonValue

    // ...

    static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday) =>
        personBirthday.Value.Year < 1809;

    static bool IsCounterPersonYear(long personKey) =>
        new DateTime(personKey).Year < 1809;

    static bool IsCounterPersonYear(int year) =>
        year < 1809;

    static bool IsCounterPersonYear(string year) =>
        new string[] { year, "1809" }.Min() == year;

    static bool IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday) =>
        isWrongYear is null || isWrongYear.Value || IsCounterPersonBirthday(personBirthday);

    string TestStatic_GetDateTime(string personKeyFormatted) =>
        GetDateTime(personKeyFormatted);
    static string GetDateTime(string personKeyFormatted) =>
            personKeyFormatted.Length < 5 || !personKeyFormatted.Contains('#') ? personKeyFormatted : personKeyFormatted[..2] == "19" ? $"1600{personKeyFormatted[4..]}" : $"1700{personKeyFormatted[4..]}";

    double? TestStatic_GetAge(Models.PersonBirthday birthday) =>
        GetAge(birthday);
    static double? GetAge(Models.PersonBirthday birthday) =>
        PersonBirthday.GetAge(birthday);

    int TestStatic_GetHour(bool alive, char sex) =>
        GetHour(alive, sex);
    static int GetHour(bool alive, char sex) =>
        alive ? sex is 'M' ? 5 : sex is 'F' ? 4 : sex is 'U' ? 2 : throw new NotImplementedException() : sex is 'M' ? 15 : sex is 'F' ? 14 : sex is 'U' ? 3 : throw new NotImplementedException();

    int TestStatic_GetHour(bool alive, ConsoleKey consoleKey) =>
        GetHour(alive, consoleKey);
    static int GetHour(bool alive, ConsoleKey consoleKey) =>
        GetHour(alive, consoleKey.ToString()[0]);

    Models.PersonBirthday TestStatic_GetPersonBirthday(long ticks) =>
        new(new DateTime(ticks));
    static Models.PersonBirthday GetPersonBirthday(long ticks) =>
        new(new DateTime(ticks));

    DateTime? TestStatic_GetDate(string month, string day, string year) =>
        GetDate(month, day, year);
    static DateTime? GetDate(string month, string day, string year) =>
        PersonBirthday.GetDate(month, day, year);

    string TestStatic_GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
        GetFileName(personBirthdayFormat, personBirthday);
    static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
        $"{personBirthday.Value.ToString(personBirthdayFormat)}.json";

    (int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
        GetAge(dateTime, birthday);
    static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
        PersonBirthday.GetAge(dateTime, birthday);

    (int, TimeSpan) TestStatic_GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
        GetAge(dateTimeTicks, birthday);
    static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
        PersonBirthday.GetAge(dateTimeTicks, birthday);

    string TestStatic_GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
        GetFormatted(personBirthdayFormat, personBirthday);
    static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
        personBirthday.Value.ToString(personBirthdayFormat);

    string TestStatic_GetFormatted(string personBirthdayFormat, long personKey) =>
        GetFormatted(personBirthdayFormat, personKey);
    static string GetFormatted(string personBirthdayFormat, long personKey) =>
        GetFormatted(personBirthdayFormat, GetPersonBirthday(personKey));

    TimeSpan? TestStatic_Get(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
        GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);
    static TimeSpan? GetTimeSpan(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
        PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);

    Models.PersonBirthday? TestStatic_GetPersonBirthday(string personBirthdayFormat, string personKeyFormatted) =>
        GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
    static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKeyFormatted) =>
        PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);

    TimeSpan? TestStatic_Get(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
        GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
    static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
        PersonBirthday.GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);

    TimeSpan? TestStatic_Get(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
        GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
    static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
        PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);

    DateTime? TestStatic_GetDateTime(string personBirthdayFormat, string personKeyFormatted) =>
        GetDateTime(personBirthdayFormat, personKeyFormatted);
    static DateTime? GetDateTime(string personBirthdayFormat, string personKeyFormatted) =>
        DateTime.TryParseExact(GetDateTime(personKeyFormatted), personBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;

    List<PersonKeyFormattedAndPersonBirthday> TestStatic_GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectoryName) =>
        GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectoryName);
    static List<PersonKeyFormattedAndPersonBirthday> GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectoryName) =>
       PersonBirthday.GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectoryName);

}