// Platform registry. Each supported platform exports a Platform descriptor
// implementing the interface below. Adding a new platform = drop in a new file
// here and register it.
//
// Platform interface:
//   {
//     id: 'facebook' | 'linkedin' | 'twitter' | ...
//     name: string                  — human-readable name
//     icon: string                  — emoji or URL
//     baseUrl: string               — main entry point (used to detect tabs)
//     hostPatterns: string[]        — manifest host_permissions patterns
//     supports: { groups, marketplace, profile, page, story, reel, ... }
//     contentScript: string         — path to platform-specific script
//   }

const PLATFORMS = {
  facebook: {
    id: 'facebook',
    name: 'פלטפורמה ראשית',  // intentionally generic in UI
    icon: '📡',
    baseUrl: 'https://www.facebook.com/',
    hostPatterns: ['https://www.facebook.com/*', 'https://web.facebook.com/*'],
    supports: {
      groups: true, marketplace: true, profile: true, page: true,
      story: true, reel: true, event: true, share: true, album: true,
      comments: true, autoJoin: true, search: true,
    },
    contentScript: 'content/fb-content.js',
  },
  linkedin: {
    id: 'linkedin',
    name: 'LinkedIn',
    icon: '💼',
    baseUrl: 'https://www.linkedin.com/',
    hostPatterns: ['https://www.linkedin.com/*'],
    supports: {
      groups: true, profile: true, page: true,
      article: true, // long-form
      story: false, reel: false, marketplace: false,
      event: true, share: true, album: false,
      comments: true, autoJoin: true, search: true,
    },
    contentScript: 'content/linkedin-content.js',
  },
  twitter: {
    id: 'twitter',
    name: 'X (Twitter)',
    icon: '𝕏',
    baseUrl: 'https://x.com/',
    hostPatterns: ['https://twitter.com/*', 'https://x.com/*'],
    supports: {
      groups: false,         // X "Communities" — similar concept
      community: true,
      profile: true,
      reply: true,
      quote: true,
      thread: true,
      poll: true,
      story: false,
      reel: false,
      marketplace: false,
      event: false,
      share: true,           // Retweet
      comments: true,
      autoJoin: false,
      search: true,
    },
    contentScript: 'content/twitter-content.js',
    constraints: {
      maxChars: 280,         // Free tier — premium goes higher
    },
  },
  reddit: {
    id: 'reddit',
    name: 'Reddit',
    icon: '🟠',
    baseUrl: 'https://www.reddit.com/',
    hostPatterns: ['https://www.reddit.com/*', 'https://new.reddit.com/*', 'https://old.reddit.com/*'],
    supports: {
      groups: true,        // Subreddits ARE groups
      profile: true,
      poll: true,
      comments: true,
      autoJoin: false,     // Reddit "joining" is just following — not part of posting
      search: true,
    },
    contentScript: 'content/reddit-content.js',
    constraints: {
      titleMaxChars: 300,
      bodyMaxChars: 40000,
    },
    notes: 'Subreddit-specific rules apply. Many require flair, minimum karma, or account age.',
  },
  instagram: {
    id: 'instagram',
    name: 'Instagram',
    icon: '📷',
    baseUrl: 'https://www.instagram.com/',
    hostPatterns: ['https://www.instagram.com/*'],
    supports: {
      groups: false,
      profile: true,
      story: true,          // best-effort
      reel: true,           // best-effort
      poll: false,
      marketplace: false,
      comments: true,
      autoJoin: false,
      search: true,
    },
    contentScript: 'content/instagram-content.js',
    constraints: {
      mediaRequired: true,
      captionMaxChars: 2200,
      maxImagesPerPost: 10,  // Carousel
    },
    notes: 'Instagram web composer (2024+) supports posts, carousels, and Reels. Stories from web are limited. Media is required — text-only posts not supported.',
  },
};

export function listPlatforms() {
  return Object.values(PLATFORMS);
}

export function getPlatform(id) {
  return PLATFORMS[id] || null;
}

// Active platform: for now we have only one. In the future this returns
// based on user preference / detected tab.
export function getActivePlatform() {
  return PLATFORMS.facebook;
}
