using NodaTime;

namespace Catalogger.Backend.Database.Models;

public record ConfigExport(
    ulong Id,
    ChannelsBackup Channels,
    string[] BannedSystems,
    ulong[] KeyRoles,
    IEnumerable<InviteExport> Invites,
    IEnumerable<WatchlistExport> Watchlist
);

public record InviteExport(string Code, string Name);

public record WatchlistExport(ulong UserId, Instant AddedAt, ulong ModeratorId, string Reason);

public class ChannelsBackup
{
    public List<ulong> IgnoredChannels { get; init; } = [];
    public List<ulong> IgnoredUsers { get; init; } = [];
    public Dictionary<ulong, List<ulong>> IgnoredUsersPerChannel { get; init; } = [];
    public Dictionary<ulong, ulong> Redirects { get; init; } = [];

    public ulong GuildUpdate { get; init; }
    public ulong GuildEmojisUpdate { get; init; }
    public ulong GuildRoleCreate { get; init; }
    public ulong GuildRoleUpdate { get; init; }
    public ulong GuildRoleDelete { get; init; }
    public ulong ChannelCreate { get; init; }
    public ulong ChannelUpdate { get; init; }
    public ulong ChannelDelete { get; init; }
    public ulong GuildMemberAdd { get; init; }
    public ulong GuildMemberUpdate { get; init; }
    public ulong GuildKeyRoleUpdate { get; init; }
    public ulong GuildMemberNickUpdate { get; init; }
    public ulong GuildMemberAvatarUpdate { get; init; }
    public ulong GuildMemberTimeout { get; init; }
    public ulong GuildMemberRemove { get; init; }
    public ulong GuildMemberKick { get; init; }
    public ulong GuildBanAdd { get; init; }
    public ulong GuildBanRemove { get; init; }
    public ulong InviteCreate { get; init; }
    public ulong InviteDelete { get; init; }
    public ulong MessageUpdate { get; init; }
    public ulong MessageDelete { get; init; }
    public ulong MessageDeleteBulk { get; init; }

    public Guild.ChannelConfig ToGuildConfig() =>
        new()
        {
            IgnoredChannels = IgnoredChannels,
            IgnoredUsers = IgnoredUsers,
            IgnoredUsersPerChannel = IgnoredUsersPerChannel,
            Redirects = Redirects,
            GuildUpdate = GuildUpdate,
            GuildEmojisUpdate = GuildEmojisUpdate,
            GuildRoleCreate = GuildRoleCreate,
            GuildRoleUpdate = GuildRoleUpdate,
            GuildRoleDelete = GuildRoleDelete,
            ChannelCreate = ChannelCreate,
            ChannelUpdate = ChannelUpdate,
            ChannelDelete = ChannelDelete,
            GuildMemberAdd = GuildMemberAdd,
            GuildMemberUpdate = GuildMemberUpdate,
            GuildKeyRoleUpdate = GuildKeyRoleUpdate,
            GuildMemberNickUpdate = GuildMemberNickUpdate,
            GuildMemberAvatarUpdate = GuildMemberAvatarUpdate,
            GuildMemberTimeout = GuildMemberTimeout,
            GuildMemberRemove = GuildMemberRemove,
            GuildMemberKick = GuildMemberKick,
            GuildBanAdd = GuildBanAdd,
            GuildBanRemove = GuildBanRemove,
            InviteCreate = InviteCreate,
            InviteDelete = InviteDelete,
            MessageUpdate = MessageUpdate,
            MessageDelete = MessageDelete,
            MessageDeleteBulk = MessageDeleteBulk,
        };

    public static ChannelsBackup FromGuildConfig(Guild.ChannelConfig channels) =>
        new()
        {
            IgnoredChannels = channels.IgnoredChannels,
            IgnoredUsers = channels.IgnoredUsers,
            IgnoredUsersPerChannel = channels.IgnoredUsersPerChannel,
            Redirects = channels.Redirects,
            GuildUpdate = channels.GuildUpdate,
            GuildEmojisUpdate = channels.GuildEmojisUpdate,
            GuildRoleCreate = channels.GuildRoleCreate,
            GuildRoleUpdate = channels.GuildRoleUpdate,
            GuildRoleDelete = channels.GuildRoleDelete,
            ChannelCreate = channels.ChannelCreate,
            ChannelUpdate = channels.ChannelUpdate,
            ChannelDelete = channels.ChannelDelete,
            GuildMemberAdd = channels.GuildMemberAdd,
            GuildMemberUpdate = channels.GuildMemberUpdate,
            GuildKeyRoleUpdate = channels.GuildKeyRoleUpdate,
            GuildMemberNickUpdate = channels.GuildMemberNickUpdate,
            GuildMemberAvatarUpdate = channels.GuildMemberAvatarUpdate,
            GuildMemberTimeout = channels.GuildMemberTimeout,
            GuildMemberRemove = channels.GuildMemberRemove,
            GuildMemberKick = channels.GuildMemberKick,
            GuildBanAdd = channels.GuildBanAdd,
            GuildBanRemove = channels.GuildBanRemove,
            InviteCreate = channels.InviteCreate,
            InviteDelete = channels.InviteDelete,
            MessageUpdate = channels.MessageUpdate,
            MessageDelete = channels.MessageDelete,
            MessageDeleteBulk = channels.MessageDeleteBulk,
        };
}
