using System.Text.RegularExpressions;

namespace AyCode.Core.Consts;

public static partial class AcRegExpression
{
    //public const string EmailMask = @"^[\w\.-]+@[\w-]+\.[a-zA-Z]{2,}(?:\.[a-zA-Z]{2,})?$";
    //public const string EmailMask = @"([\w\.-])+@([\w-])+\.(\w|-){2,4}(?:\.[a-zA-Z]{2,4})?";
    public const string EmailMask = @"((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?";
    //public const string EmailMask = @"[\w\.-]+@[a-zA-Z\d-]+.[a-zA-Z]{2,}(.[a-zA-Z]{2,})?";
    //public const string EmailMask = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}"; //original
    //public const string PhoneNumberMask = @"\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*\d\W*(\d{1,2})";
    public const string PhoneNumberMask = @"\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\W*\d(\W*\d){1,14}";

    /// <summary>Rendszám (EKÁER-kompatibilis): nagybetű + szám (+ <c>Ö Ő Ü Ű</c>), 4–15 karakter — kötőjel/szóköz NÉLKÜL.</summary>
    public const string PlateNumberMask = "[A-Z0-9ÖŐÜŰ]{4,15}";

    /// <summary>Országkód, ISO 3166-1 alpha-2: pontosan 2 nagybetű (pl. <c>HU</c>).</summary>
    public const string CountryCodeAlpha2Mask = "[A-Z]{2}";

    /// <summary>Országkód: 1–3 nagybetű (pl. jármű-országkód az EKÁER-ben).</summary>
    public const string CountryCodeMax3Mask = "[A-Z]{1,3}";

    [GeneratedRegex(AcRegExpression.EmailMask)]
    public static partial Regex EmailRegex();

    [GeneratedRegex(AcRegExpression.PhoneNumberMask)]
    public static partial Regex PhoneNumberRegex();

    // A Regex-eket horgonyozzuk (^…$): a const Mask nyers (a [RegularExpression] attribútum maga
    // teljes-string egyezést vár), de az IsMatch különben részstringet is elfogadna.
    [GeneratedRegex("^" + AcRegExpression.PlateNumberMask + "$")]
    public static partial Regex PlateNumberRegex();

    [GeneratedRegex("^" + AcRegExpression.CountryCodeAlpha2Mask + "$")]
    public static partial Regex CountryCodeAlpha2Regex();

    [GeneratedRegex("^" + AcRegExpression.CountryCodeMax3Mask + "$")]
    public static partial Regex CountryCodeMax3Regex();
}