import { z } from 'zod';

export const SocialFeedTypeSchema = z.enum(['TWITCH', 'YOUTUBE', 'RSS', 'REDDIT']);
export type SocialFeedType = z.infer<typeof SocialFeedTypeSchema>;

export const GuildBackupPayloadSchema = z.object({
  version: z.literal(1),
  guildName: z.string(),
  roles: z.array(
    z.object({
      id: z.string(),
      name: z.string(),
      color: z.number(),
      hoist: z.boolean(),
      mentionable: z.boolean(),
      permissions: z.string(),
      position: z.number()
    })
  ),
  channels: z.array(
    z.object({
      id: z.string(),
      name: z.string(),
      type: z.number(),
      parentId: z.string().nullable(),
      position: z.number(),
      topic: z.string().nullable().optional(),
      nsfw: z.boolean().optional(),
      rateLimitPerUser: z.number().optional(),
      bitrate: z.number().optional(),
      userLimit: z.number().optional(),
      permissionOverwrites: z.array(
        z.object({
          id: z.string(),
          type: z.number(),
          allow: z.string(),
          deny: z.string()
        })
      )
    })
  ),
  settings: z
    .object({
      name: z.string().optional(),
      verificationLevel: z.number().optional(),
      explicitContentFilter: z.number().optional(),
      defaultMessageNotifications: z.number().optional(),
      afkTimeout: z.number().optional()
    })
    .optional()
});
export type GuildBackupPayload = z.infer<typeof GuildBackupPayloadSchema>;

export function applyCountTemplate(template: string, count: number): string {
  return template.replaceAll('{count}', String(count));
}

export function applyFeedTemplate(
  template: string,
  vars: Record<string, string>
): string {
  return Object.entries(vars).reduce(
    (acc, [key, value]) => acc.replaceAll(`{${key}}`, value),
    template
  );
}
