using MediatR;

namespace MktXService.API.Application.Queries;

#region Twitter Account Queries

public record GetTwitterAccountsQuery(Guid MerchantId) : IRequest<IEnumerable<TwitterAccountDto>>;

public record GetTwitterAccountQuery(Guid AccountId) : IRequest<TwitterAccountDto?>;

public record TwitterAccountDto(
    Guid Id,
    Guid MerchantId,
    string TwitterUserId,
    string Username,
    string? DisplayName,
    string? ProfileImageUrl,
    string Status,
    DateTime ConnectedAt);

#endregion

#region Campaign Queries

public record GetCampaignsQuery(
    Guid MerchantId,
    string? Status = null,
    int Skip = 0,
    int Take = 20
) : IRequest<IEnumerable<CampaignDto>>;

public record GetCampaignQuery(Guid CampaignId) : IRequest<CampaignDetailDto?>;

public record CampaignDto(
    Guid Id,
    string Name,
    string Type,
    string Status,
    int TotalSent,
    int TotalDelivered,
    DateTime CreatedAt);

public record CampaignDetailDto(
    Guid Id,
    string Name,
    string Type,
    string Status,
    Guid? TemplateId,
    List<Guid> SegmentIds,
    CampaignMetricsDto Metrics,
    CampaignScheduleDto? Schedule,
    DateTime CreatedAt);

public record CampaignMetricsDto(int Sent, int Delivered, int Opened, int Clicked, int Replied, int Failed);

public record CampaignScheduleDto(DateTime? StartAt, DateTime? EndAt, string? Recurrence);

#endregion

#region Conversation Queries

public record GetConversationsQuery(
    Guid AccountId,
    string? Status = null,
    Guid? AssignedToUserId = null,
    int Skip = 0,
    int Take = 20
) : IRequest<IEnumerable<ConversationDto>>;

public record GetConversationQuery(Guid ConversationId, bool IncludeMessages = true) 
    : IRequest<ConversationDetailDto?>;

public record ConversationDto(
    Guid Id,
    Guid ContactId,
    string ContactUsername,
    string Status,
    int MessageCount,
    DateTime StartedAt,
    DateTime? LastMessageAt);

public record ConversationDetailDto(
    Guid Id,
    Guid ContactId,
    ContactSummaryDto Contact,
    string Status,
    Guid? AssignedToUserId,
    List<MessageDto> Messages,
    DateTime StartedAt,
    DateTime? ClosedAt);

public record ContactSummaryDto(
    Guid Id,
    string TwitterUserId,
    string Username,
    string? DisplayName,
    string? ProfileImageUrl);

public record MessageDto(
    Guid Id,
    string Direction,
    string Type,
    string Content,
    bool IsFromBot,
    DateTime SentAt);

#endregion

#region Contact Queries

public record GetContactsQuery(
    Guid AccountId,
    string? SearchTerm = null,
    List<string>? Tags = null,
    int Skip = 0,
    int Take = 20
) : IRequest<IEnumerable<ContactDto>>;

public record GetContactQuery(Guid ContactId) : IRequest<ContactDetailDto?>;

public record ContactDto(
    Guid Id,
    string TwitterUserId,
    string Username,
    string? DisplayName,
    List<string> Tags,
    DateTime? LastInteractionAt);

public record ContactDetailDto(
    Guid Id,
    string TwitterUserId,
    string Username,
    string? DisplayName,
    string? ProfileImageUrl,
    string Source,
    Dictionary<string, object> Attributes,
    List<string> Tags,
    DateTime FirstInteractionAt,
    DateTime? LastInteractionAt);

#endregion

#region Template Queries

public record GetTemplatesQuery(
    Guid MerchantId,
    string? Type = null
) : IRequest<IEnumerable<TemplateDto>>;

public record GetTemplateQuery(Guid TemplateId) : IRequest<TemplateDetailDto?>;

public record TemplateDto(
    Guid Id,
    string Name,
    string Type,
    DateTime CreatedAt);

public record TemplateDetailDto(
    Guid Id,
    string Name,
    string Type,
    string Content,
    List<string> Variables,
    DateTime CreatedAt);

#endregion
