using System.Text.Json.Serialization;

namespace MktZaloService.Infrastructure.Zalo.Models;

/// <summary>
/// EN: Base response from Zalo API.
/// VI: Response cơ bản từ Zalo API.
/// </summary>
public class ZaloApiResponse
{
    [JsonPropertyName("error")]
    public int Error { get; set; }

    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

/// <summary>
/// EN: Response from sending a message via Zalo API.
/// VI: Response từ việc gửi tin nhắn qua Zalo API.
/// </summary>
public class ZaloSendMessageResponse : ZaloApiResponse
{
    [JsonPropertyName("data")]
    public ZaloSendMessageData? Data { get; set; }
}

public class ZaloSendMessageData
{
    [JsonPropertyName("message_id")]
    public string? MessageId { get; set; }
}

/// <summary>
/// EN: Response from getting user profile.
/// VI: Response từ việc lấy thông tin user.
/// </summary>
public class ZaloUserProfileResponse : ZaloApiResponse
{
    [JsonPropertyName("data")]
    public ZaloUserProfileData? Data { get; set; }
}

public class ZaloUserProfileData
{
    [JsonPropertyName("user_id")]
    public string? UserId { get; set; }

    [JsonPropertyName("display_name")]
    public string? DisplayName { get; set; }

    [JsonPropertyName("avatar")]
    public string? Avatar { get; set; }

    [JsonPropertyName("user_gender")]
    public int? Gender { get; set; }
}

/// <summary>
/// EN: Webhook event from Zalo.
/// VI: Sự kiện webhook từ Zalo.
/// </summary>
public class ZaloWebhookEvent
{
    [JsonPropertyName("app_id")]
    public string? AppId { get; set; }

    [JsonPropertyName("event_name")]
    public string? EventName { get; set; }

    [JsonPropertyName("timestamp")]
    public long Timestamp { get; set; }

    [JsonPropertyName("sender")]
    public ZaloWebhookSender? Sender { get; set; }

    [JsonPropertyName("recipient")]
    public ZaloWebhookRecipient? Recipient { get; set; }

    [JsonPropertyName("message")]
    public ZaloWebhookMessage? Message { get; set; }

    [JsonPropertyName("follower")]
    public ZaloWebhookFollower? Follower { get; set; }
}

public class ZaloWebhookSender
{
    [JsonPropertyName("id")]
    public string? Id { get; set; }
}

public class ZaloWebhookRecipient
{
    [JsonPropertyName("id")]
    public string? Id { get; set; }
}

public class ZaloWebhookMessage
{
    [JsonPropertyName("text")]
    public string? Text { get; set; }

    [JsonPropertyName("msg_id")]
    public string? MessageId { get; set; }

    [JsonPropertyName("attachments")]
    public List<ZaloWebhookAttachment>? Attachments { get; set; }
}

public class ZaloWebhookAttachment
{
    [JsonPropertyName("type")]
    public string? Type { get; set; }

    [JsonPropertyName("payload")]
    public ZaloAttachmentPayload? Payload { get; set; }
}

public class ZaloAttachmentPayload
{
    [JsonPropertyName("url")]
    public string? Url { get; set; }

    [JsonPropertyName("thumbnail")]
    public string? Thumbnail { get; set; }
}

public class ZaloWebhookFollower
{
    [JsonPropertyName("id")]
    public string? Id { get; set; }
}

/// <summary>
/// EN: Request to send a text message.
/// VI: Yêu cầu gửi tin nhắn văn bản.
/// </summary>
public class ZaloSendTextRequest
{
    [JsonPropertyName("recipient")]
    public ZaloMessageRecipient Recipient { get; set; } = new();

    [JsonPropertyName("message")]
    public ZaloTextMessage Message { get; set; } = new();
}

public class ZaloMessageRecipient
{
    [JsonPropertyName("user_id")]
    public string UserId { get; set; } = string.Empty;
}

public class ZaloTextMessage
{
    [JsonPropertyName("text")]
    public string Text { get; set; } = string.Empty;
}

/// <summary>
/// EN: Request to send a ZNS template message.
/// VI: Yêu cầu gửi tin nhắn mẫu ZNS.
/// </summary>
public class ZaloSendTemplateRequest
{
    [JsonPropertyName("phone")]
    public string Phone { get; set; } = string.Empty;

    [JsonPropertyName("template_id")]
    public string TemplateId { get; set; } = string.Empty;

    [JsonPropertyName("template_data")]
    public Dictionary<string, string> TemplateData { get; set; } = new();
}
