namespace FacebookService.Infrastructure.ExternalServices;

/// <summary>
/// EN: Interface for Facebook Messenger API client.
/// VI: Interface cho Facebook Messenger API client.
/// </summary>
public interface IFacebookMessengerClient
{
    /// <summary>
    /// EN: Send a text message to a user.
    /// VI: Gửi tin nhắn văn bản đến người dùng.
    /// </summary>
    Task<SendMessageResult> SendTextMessageAsync(
        string recipientId,
        string message,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Send a message with quick replies.
    /// VI: Gửi tin nhắn với quick replies.
    /// </summary>
    Task<SendMessageResult> SendQuickRepliesAsync(
        string recipientId,
        string message,
        IEnumerable<QuickReply> quickReplies,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Send a generic template (cards).
    /// VI: Gửi template generic (cards).
    /// </summary>
    Task<SendMessageResult> SendGenericTemplateAsync(
        string recipientId,
        IEnumerable<TemplateElement> elements,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Send a button template.
    /// VI: Gửi template button.
    /// </summary>
    Task<SendMessageResult> SendButtonTemplateAsync(
        string recipientId,
        string text,
        IEnumerable<TemplateButton> buttons,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Get user profile from Facebook.
    /// VI: Lấy thông tin người dùng từ Facebook.
    /// </summary>
    Task<FacebookUserProfile?> GetUserProfileAsync(
        string userId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Mark message as seen.
    /// VI: Đánh dấu tin nhắn đã xem.
    /// </summary>
    Task<bool> MarkAsSeenAsync(
        string recipientId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// EN: Show typing indicator.
    /// VI: Hiển thị indicator đang gõ.
    /// </summary>
    Task<bool> ShowTypingAsync(
        string recipientId,
        bool isTyping = true,
        CancellationToken cancellationToken = default);
}

#region Models

public record SendMessageResult(
    bool Success,
    string? MessageId = null,
    string? RecipientId = null,
    string? Error = null
);

public record QuickReply(
    string ContentType, // "text", "user_phone_number", "user_email"
    string? Title = null,
    string? Payload = null,
    string? ImageUrl = null
);

public record TemplateElement(
    string Title,
    string? Subtitle = null,
    string? ImageUrl = null,
    TemplateButton? DefaultAction = null,
    IEnumerable<TemplateButton>? Buttons = null
);

public record TemplateButton(
    string Type, // "web_url", "postback", "phone_number"
    string Title,
    string? Url = null,
    string? Payload = null
);

public record FacebookUserProfile(
    string Id,
    string? FirstName,
    string? LastName,
    string? ProfilePic,
    string? Locale,
    float? Timezone
);

#endregion
