using Ikar.Shared;

namespace Ikar.Server.Infrastructure.Admin;

public sealed record AdminSessionStateDto(
    bool Configured,
    bool Authenticated,
    string? Username);

public sealed record AdminStatusDto(
    string Environment,
    string ServerVersion,
    DateTimeOffset StartedAtUtc,
    DateTimeOffset CurrentTimeUtc,
    bool DatabaseReachable,
    string? DatabaseConnection,
    int TotalUsers,
    int BlockedUsers,
    int BotUsers,
    int TotalBots,
    int EnabledBots,
    int TotalChats,
    int DirectChats,
    int GroupChats,
    int ChannelChats,
    int ProtectedChats,
    int TotalMessages,
    int ProtectedMessages,
    int ExpiringMessages,
    int PinnedMessages,
    int TotalAttachments,
    long AttachmentBytes,
    int TotalStories,
    int ActiveStories,
    int ProtectedStories,
    int ActiveSessions,
    int RegisteredPushDevices,
    int PendingJoinRequests,
    int ActiveInviteLinks,
    int Topics,
    int ModerationEvents,
    int ProcessId);

public sealed record AdminUserDto(
    Guid Id,
    string Username,
    string DisplayName,
    bool IsBlocked,
    bool IsBot,
    DateTimeOffset CreatedAt,
    DateTimeOffset? BlockedAt,
    DateTimeOffset? LastSeenAt,
    string? PhoneNumber,
    string? About,
    string? ClientPlatform,
    int? ClientVersionCode,
    string? ClientVersionName,
    IReadOnlyList<AdminUserClientVersionDto> ClientVersions,
    int ActiveSessions,
    int PushDevices,
    int ChatMemberships,
    int MessagesSent,
    int Reactions,
    bool PasscodeLockEnabled,
    bool ShowMessagePreview);

public sealed record AdminUserClientVersionDto(
    string? ClientPlatform,
    int? ClientVersionCode,
    string? ClientVersionName,
    DateTimeOffset LastSeenAt,
    int Sessions,
    int PushDevices);

public sealed record AdminChatDto(
    Guid Id,
    string Type,
    string Title,
    string CreatedBy,
    DateTimeOffset CreatedAt,
    DateTimeOffset? LastActivityAt,
    int Members,
    int Messages,
    int Attachments,
    int PinnedMessages,
    int ProtectedMessages,
    int InviteLinks,
    int PendingJoinRequests,
    int Topics,
    string? PublicUsername,
    bool TopicsEnabled,
    bool HasProtectedContent,
    int? DefaultMessageTtlSeconds);

public sealed record AdminAttachmentDto(
    Guid Id,
    Guid ChatId,
    Guid MessageId,
    string ChatTitle,
    string UploadedBy,
    string FileName,
    string ContentType,
    long FileSizeBytes,
    int SortOrder,
    Guid? MediaAlbumId,
    DateTimeOffset UploadedAt,
    bool Exists,
    bool IsProtected,
    string DownloadPath);

public sealed record AdminChatDetailsDto(
    AdminChatDto Chat,
    IReadOnlyList<AdminChatMemberDto> Members,
    IReadOnlyList<AdminChatInviteLinkDto> InviteLinks,
    IReadOnlyList<AdminChatJoinRequestDto> JoinRequests,
    IReadOnlyList<AdminChatTopicDto> Topics,
    IReadOnlyList<AdminMessagePreviewDto> RecentMessages,
    IReadOnlyList<AdminModerationLogItemDto> ModerationLog);

public sealed record AdminChatMemberDto(
    Guid UserId,
    string Username,
    string DisplayName,
    bool IsBot,
    ChatMemberRole Role,
    bool IsOwner,
    bool CanPinMessages,
    bool CanDeleteMessages,
    bool CanInviteUsers,
    bool CanPostMessages,
    bool IsArchived,
    bool IsPinned,
    DateTimeOffset? MutedUntil,
    string? FolderKey,
    DateTimeOffset JoinedAt,
    DateTimeOffset? LastReadAt);

public sealed record AdminChatInviteLinkDto(
    Guid Id,
    string Token,
    string Link,
    string? Title,
    bool CreatesJoinRequest,
    bool IsRevoked,
    DateTimeOffset CreatedAt,
    DateTimeOffset? RevokedAt);

public sealed record AdminChatJoinRequestDto(
    Guid Id,
    Guid InviteLinkId,
    string Username,
    string DisplayName,
    ChatJoinRequestStatus Status,
    DateTimeOffset RequestedAt,
    DateTimeOffset? ResolvedAt,
    string? ResolvedBy);

public sealed record AdminChatTopicDto(
    Guid Id,
    string Title,
    string Icon,
    bool IsPinned,
    bool IsClosed,
    DateTimeOffset CreatedAt,
    DateTimeOffset LastActivityAt,
    int MessageCount);

public sealed record AdminMessagePreviewDto(
    Guid Id,
    string Sender,
    string Text,
    DateTimeOffset SentAt,
    DateTimeOffset? EditedAt,
    DateTimeOffset? DeletedAt,
    bool HasProtectedContent,
    Guid? MediaAlbumId,
    int Attachments,
    int Reactions);

public sealed record AdminModerationLogItemDto(
    long Id,
    Guid? ChatId,
    string ActorDisplayName,
    ModerationLogTargetType TargetType,
    Guid? TargetId,
    string Action,
    string? Reason,
    DateTimeOffset CreatedAt);

public sealed record AdminChatSettingsRequest(
    string? PublicUsername,
    bool TopicsEnabled,
    bool HasProtectedContent,
    int? DefaultMessageTtlSeconds);

public sealed record AdminChatMemberPermissionsRequest(
    ChatMemberRole Role,
    bool CanPinMessages,
    bool CanDeleteMessages,
    bool CanInviteUsers,
    bool CanPostMessages);

public sealed record AdminCreateInviteLinkRequest(
    string? Title,
    bool CreatesJoinRequest);

public sealed record AdminResolveJoinRequestRequest(bool Approve);

public sealed record AdminExpiredMessagesCleanupDto(
    int DeletedMessages,
    int DeletedAttachments);

public sealed record AdminAndroidUpdateCompatibilityReportDto(
    DateTimeOffset CurrentTimeUtc,
    int TotalHitsLast24Hours,
    int TotalHitsLast7Days,
    int HitsWithoutVersionLast24Hours,
    int HitsWithoutVersionLast7Days,
    DateTimeOffset? LatestHitAt,
    IReadOnlyList<AdminAndroidUpdateCompatibilityRouteDto> RoutesLast7Days,
    IReadOnlyList<AdminAndroidUpdateCompatibilityVersionDto> VersionsLast7Days,
    IReadOnlyList<AdminAndroidUpdateCompatibilityHitDto> RecentHits);

public sealed record AdminAndroidUpdateCompatibilityRouteDto(
    string Route,
    int HitsLast24Hours,
    int HitsLast7Days,
    DateTimeOffset? LatestHitAt);

public sealed record AdminAndroidUpdateCompatibilityVersionDto(
    string ClientPlatform,
    int? ClientVersionCode,
    string? ClientVersionName,
    int HitsLast24Hours,
    int HitsLast7Days,
    DateTimeOffset? LatestHitAt);

public sealed record AdminAndroidUpdateCompatibilityHitDto(
    DateTimeOffset HitAt,
    string Route,
    string RequestPath,
    string? RequestedFileName,
    string? ClientPlatform,
    int? ClientVersionCode,
    string? ClientVersionName,
    string? RemoteIp,
    string? UserAgent);
