using System.Linq;
using JobsMedical.Web.Models;

namespace JobsMedical.Web.Services;

/// <summary>Presentation helpers for <see cref="ContactType"/> — label, icon, and a clickable href.</summary>
public static class ContactInfo
{
    public static string Label(ContactType t) => t switch
    {
        ContactType.Mobile => "موبایل",
        ContactType.Phone => "تلفن ثابت",
        ContactType.Email => "ایمیل",
        ContactType.Telegram => "تلگرام",
        ContactType.Bale => "بله",
        ContactType.WhatsApp => "واتساپ",
        ContactType.Instagram => "اینستاگرام",
        ContactType.Website => "وب‌سایت",
        _ => "تماس",
    };

    public static string Icon(ContactType t) => t switch
    {
        ContactType.Mobile or ContactType.Phone => "📞",
        ContactType.Email => "✉️",
        ContactType.Telegram => "📨",
        ContactType.Bale => "💬",
        ContactType.WhatsApp => "🟢",
        ContactType.Instagram => "📷",
        ContactType.Website => "🌐",
        _ => "🔗",
    };

    /// <summary>A clickable URL for the contact (tel:/mailto:/t.me/…), or null when not linkable.</summary>
    public static string? Href(ContactType t, string value)
    {
        var v = value.Trim();
        var handle = v.TrimStart('@');
        string Digits() => new(v.Where(char.IsDigit).ToArray());
        return t switch
        {
            ContactType.Mobile or ContactType.Phone => "tel:" + Digits(),
            ContactType.Email => "mailto:" + v,
            ContactType.Telegram => "https://t.me/" + handle,
            ContactType.Bale => "https://ble.ir/" + handle,
            ContactType.WhatsApp => "https://wa.me/" + Digits(),
            ContactType.Instagram => "https://instagram.com/" + handle,
            ContactType.Website => v.StartsWith("http") ? v : "https://" + v,
            _ => null,
        };
    }
}
