export type Category = {
  id: string
  slug: string
  name_tr: string
  name_en: string
  description_tr: string
  description_en: string
  icon: string
  color: string
  thread_count: number
}

export type Profile = {
  id: string
  username: string
  display_name: string
  avatar_url: string | null
  bio: string | null
  locale: string
  created_at: string
  thread_count: number
  comment_count: number
  reputation: number
}

export type Thread = {
  id: string
  title: string
  content: string
  user_id: string
  category_id: string
  is_pinned: boolean
  is_locked: boolean
  view_count: number
  vote_count: number
  comment_count: number
  created_at: string
  updated_at: string
  author: Profile
  category: Category
}

export type Comment = {
  id: string
  content: string
  user_id: string
  thread_id: string
  parent_id: string | null
  vote_count: number
  created_at: string
  updated_at: string
  author: Profile
  replies?: Comment[]
}

export const mockCategories: Category[] = [
  {
    id: "cat-1",
    slug: "tarih",
    name_tr: "Tarih",
    name_en: "History",
    description_tr: "Tarihi olaylar, gizli operasyonlar ve gecmisten dersler.",
    description_en: "Historical events, covert operations, and lessons from the past.",
    icon: "Landmark",
    color: "#8B4513",
    thread_count: 24,
  },
  {
    id: "cat-2",
    slug: "politika",
    name_tr: "Politika",
    name_en: "Politics",
    description_tr: "Siyasi analiz, iktidar yapilari ve karar mekanizmalari.",
    description_en: "Political analysis, power structures, and decision-making.",
    icon: "Scale",
    color: "#1a365d",
    thread_count: 42,
  },
  {
    id: "cat-3",
    slug: "ekonomi",
    name_tr: "Ekonomi",
    name_en: "Economy",
    description_tr: "Ekonomik yapilarin arka plani, finansal sistemler.",
    description_en: "Economic structures, financial systems, and their backgrounds.",
    icon: "TrendingUp",
    color: "#065f46",
    thread_count: 18,
  },
  {
    id: "cat-4",
    slug: "istihbarat",
    name_tr: "Istihbarat",
    name_en: "Intelligence",
    description_tr: "Istihbarat orgutleri, operasyonlar ve stratejiler.",
    description_en: "Intelligence agencies, operations, and strategies.",
    icon: "Eye",
    color: "#4c1d95",
    thread_count: 31,
  },
  {
    id: "cat-5",
    slug: "medya",
    name_tr: "Medya",
    name_en: "Media",
    description_tr: "Medya manipulasyonu, propaganda ve enformasyon savasi.",
    description_en: "Media manipulation, propaganda, and information warfare.",
    icon: "Radio",
    color: "#9a3412",
    thread_count: 15,
  },
  {
    id: "cat-6",
    slug: "teknoloji",
    name_tr: "Teknoloji",
    name_en: "Technology",
    description_tr: "Siber guvenlik, gozetim teknolojileri ve dijital kontrol.",
    description_en: "Cybersecurity, surveillance tech, and digital control.",
    icon: "Shield",
    color: "#0c4a6e",
    thread_count: 22,
  },
  {
    id: "cat-7",
    slug: "genel",
    name_tr: "Genel Tartisma",
    name_en: "General Discussion",
    description_tr: "Diger konularda serbest tartisma alani.",
    description_en: "Open discussion area for miscellaneous topics.",
    icon: "MessageCircle",
    color: "#525252",
    thread_count: 37,
  },
]

export const mockProfiles: Profile[] = [
  {
    id: "user-1",
    username: "tarihci_42",
    display_name: "Ahmet K.",
    avatar_url: null,
    bio: "Tarih arastirmacisi, akademisyen. Soguk Savas donemi uzmani.",
    locale: "tr",
    created_at: "2024-01-15T10:00:00Z",
    thread_count: 12,
    comment_count: 87,
    reputation: 342,
  },
  {
    id: "user-2",
    username: "analist_zeynep",
    display_name: "Zeynep D.",
    avatar_url: null,
    bio: "Siyaset bilimci. Uluslararasi iliskiler ve stratejik analiz.",
    locale: "tr",
    created_at: "2024-03-22T14:30:00Z",
    thread_count: 8,
    comment_count: 124,
    reputation: 518,
  },
  {
    id: "user-3",
    username: "deep_watcher",
    display_name: "Murat E.",
    avatar_url: null,
    bio: "Independent researcher focusing on intelligence operations.",
    locale: "en",
    created_at: "2024-06-10T09:15:00Z",
    thread_count: 15,
    comment_count: 203,
    reputation: 721,
  },
  {
    id: "user-4",
    username: "ekonomist_ali",
    display_name: "Ali Y.",
    avatar_url: null,
    bio: "Finansal sistemler ve ekonomi politikalari uzerine calismalar.",
    locale: "tr",
    created_at: "2024-08-05T16:45:00Z",
    thread_count: 6,
    comment_count: 45,
    reputation: 156,
  },
]

export const mockThreads: Thread[] = [
  {
    id: "thread-1",
    title: "Gladio Operasyonu ve Turkiye'deki Etkileri",
    content: "NATO'nun gizli ordusu Gladio'nun Turkiye'deki faaliyetleri hakkinda kapsamli bir inceleme. Soguk Savas doneminde kontr-gerilla yapilanmasi, provokasyonlar ve siyasi cinayetler uzerine belgeler ve analizler.\n\nGladio, NATO ulkelerinde Sovyet isgaline karsi direnis amaciyla kurulan ancak zamanla ic siyasete mudahale eden bir yapi olarak tarihte yerini aldi. Turkiye'de bu yapilanmanin etkileri ozellikle 1970'li ve 1980'li yillarda yogun olarak hissedildi.",
    user_id: "user-1",
    category_id: "cat-1",
    is_pinned: true,
    is_locked: false,
    view_count: 1247,
    vote_count: 89,
    comment_count: 34,
    created_at: "2025-11-10T08:30:00Z",
    updated_at: "2025-11-10T08:30:00Z",
    author: mockProfiles[0],
    category: mockCategories[0],
  },
  {
    id: "thread-2",
    title: "Merkez Bankasi Bagimsizligi: Gercek mi, Mit mi?",
    content: "Turkiye ve dunya genelinde merkez bankalarinin gercekte ne kadar bagimsiz oldugunu inceliyoruz. Siyasi baskiler, uluslararasi finansal kuruluslar ve para politikasi uzerine derinlemesine bir analiz.\n\nMerkez bankalarinin bagimsizligi modern ekonomi politikasinin temel taslarindan biri olarak kabul edilir, ancak pratikte bu bagimsizlik ne olcude gerceklesiyor?",
    user_id: "user-4",
    category_id: "cat-3",
    is_pinned: false,
    is_locked: false,
    view_count: 856,
    vote_count: 67,
    comment_count: 28,
    created_at: "2025-12-05T14:20:00Z",
    updated_at: "2025-12-05T14:20:00Z",
    author: mockProfiles[3],
    category: mockCategories[2],
  },
  {
    id: "thread-3",
    title: "The Role of Intelligence Agencies in Shaping Foreign Policy",
    content: "An in-depth analysis of how intelligence agencies like the CIA, MI6, and MIT have influenced foreign policy decisions throughout the 20th and 21st centuries. From regime changes to covert operations, the shadow of intelligence services looms large over international relations.\n\nThis thread aims to collect and analyze documented cases where intelligence agencies played a decisive role in shaping the geopolitical landscape.",
    user_id: "user-3",
    category_id: "cat-4",
    is_pinned: true,
    is_locked: false,
    view_count: 2103,
    vote_count: 156,
    comment_count: 67,
    created_at: "2025-10-18T11:00:00Z",
    updated_at: "2025-10-18T11:00:00Z",
    author: mockProfiles[2],
    category: mockCategories[3],
  },
  {
    id: "thread-4",
    title: "Medya Sahiplik Yapilari ve Haber Kontrolu",
    content: "Turkiye'de ve dunyada medya kuruluslarinin sahiplik yapilari, bunlarin haber icerigine etkileri ve enformasyon kontrolu mekanizmalari uzerine bir tartisma.\n\nAna akis medyanin arkasindaki sermaye gruplari, siyasi baglantilari ve bunlarin gazetecilik pratiklerine etkileri incelenmektedir.",
    user_id: "user-2",
    category_id: "cat-5",
    is_pinned: false,
    is_locked: false,
    view_count: 634,
    vote_count: 45,
    comment_count: 19,
    created_at: "2026-01-08T16:45:00Z",
    updated_at: "2026-01-08T16:45:00Z",
    author: mockProfiles[1],
    category: mockCategories[4],
  },
  {
    id: "thread-5",
    title: "Siber Gozetim Programlari ve Vatandas Haklari",
    content: "Devletlerin vatandaslarina yonelik siber gozetim programlari, bunlarin yasal dayanaklari ve bireysel ozgurlukler uzerindeki etkileri. Snowden ifslolari sonrasi ortaya cikan gercekler ve Turkiye'deki durum.\n\nDigital cagda mahremiyet hakki ile guvenlik ihtiyaci arasindaki denge nasil saglanmali?",
    user_id: "user-3",
    category_id: "cat-6",
    is_pinned: false,
    is_locked: false,
    view_count: 912,
    vote_count: 78,
    comment_count: 41,
    created_at: "2026-02-14T09:30:00Z",
    updated_at: "2026-02-14T09:30:00Z",
    author: mockProfiles[2],
    category: mockCategories[5],
  },
  {
    id: "thread-6",
    title: "Ergenekon Davasi: Yargilama Sureci ve Sonuclari",
    content: "2007'de baslayan Ergenekon sorusturmasi ve sonrasindaki yargilama surecinin detayli bir incelemesi. Derin devlet yapilari, yargi sureci, tahliyeler ve bu davanin Turkiye siyasetine etkileri.\n\nBu konu, Turkiye'nin yakin tarihindeki en tartismali yargilama sureclerinden birini ele almaktadir.",
    user_id: "user-1",
    category_id: "cat-2",
    is_pinned: false,
    is_locked: false,
    view_count: 1567,
    vote_count: 112,
    comment_count: 53,
    created_at: "2026-03-20T13:15:00Z",
    updated_at: "2026-03-20T13:15:00Z",
    author: mockProfiles[0],
    category: mockCategories[1],
  },
  {
    id: "thread-7",
    title: "Kripto Para ve Devlet Kontrolu",
    content: "Kripto paralarin yukselisi, devletlerin bu yeni finansal sisteme yaklasimi ve merkezi dijital para birimleri (CBDC) uzerine tartismalar. Finansal ozgurluk mu, yeni bir kontrol araci mi?",
    user_id: "user-4",
    category_id: "cat-3",
    is_pinned: false,
    is_locked: false,
    view_count: 445,
    vote_count: 34,
    comment_count: 16,
    created_at: "2026-04-02T10:00:00Z",
    updated_at: "2026-04-02T10:00:00Z",
    author: mockProfiles[3],
    category: mockCategories[2],
  },
  {
    id: "thread-8",
    title: "Sosyal Medya Algoritmalarinin Toplumsal Kutuplasmaya Etkisi",
    content: "Sosyal medya platformlarinin kullandigi algoritmalar, filtre balonlari ve bunlarin toplumsal kutuplasmaya etkileri. Bilgi kirliligi, dezenformasyon ve dijital manipulasyon teknikleri uzerine analizler.",
    user_id: "user-2",
    category_id: "cat-6",
    is_pinned: false,
    is_locked: false,
    view_count: 723,
    vote_count: 56,
    comment_count: 22,
    created_at: "2026-04-15T15:30:00Z",
    updated_at: "2026-04-15T15:30:00Z",
    author: mockProfiles[1],
    category: mockCategories[5],
  },
]

export const mockComments: Comment[] = [
  {
    id: "comment-1",
    content: "Gladio konusunda cok kapsamli bir calisma olmus. Ozellikle 1970'lerdeki provokasyonlarla ilgili belgeler oldukca dikkat cekici. Susurluk kazasi da bu yapilanmanin bir parcasi olarak degerlendirilmeli.",
    user_id: "user-2",
    thread_id: "thread-1",
    parent_id: null,
    vote_count: 23,
    created_at: "2025-11-10T10:15:00Z",
    updated_at: "2025-11-10T10:15:00Z",
    author: mockProfiles[1],
  },
  {
    id: "comment-2",
    content: "Kesinlikle katiliyorum. Susurluk aslinda buzdasinin gorunen kismi. Bu yapilanmanin kokleri cok daha derinlere gidiyor.",
    user_id: "user-3",
    thread_id: "thread-1",
    parent_id: "comment-1",
    vote_count: 15,
    created_at: "2025-11-10T11:30:00Z",
    updated_at: "2025-11-10T11:30:00Z",
    author: mockProfiles[2],
  },
  {
    id: "comment-3",
    content: "Daniele Ganser'in 'NATO's Secret Armies' kitabi bu konuda en iyi kaynaklardan biri. Turkiye bolumu ozellikle detayli.",
    user_id: "user-1",
    thread_id: "thread-1",
    parent_id: "comment-1",
    vote_count: 18,
    created_at: "2025-11-10T12:00:00Z",
    updated_at: "2025-11-10T12:00:00Z",
    author: mockProfiles[0],
  },
  {
    id: "comment-4",
    content: "Merkez bankasi bagimsizligi meselesi gercekten karmasik. IMF ve Dunya Bankasi'nin bu konudaki rolunu de eklemek lazim.",
    user_id: "user-2",
    thread_id: "thread-2",
    parent_id: null,
    vote_count: 12,
    created_at: "2025-12-05T16:00:00Z",
    updated_at: "2025-12-05T16:00:00Z",
    author: mockProfiles[1],
  },
  {
    id: "comment-5",
    content: "Excellent analysis. I would add that the Church Committee hearings in the US revealed just how deeply intelligence agencies were embedded in policy-making.",
    user_id: "user-3",
    thread_id: "thread-3",
    parent_id: null,
    vote_count: 45,
    created_at: "2025-10-18T14:00:00Z",
    updated_at: "2025-10-18T14:00:00Z",
    author: mockProfiles[2],
  },
  {
    id: "comment-6",
    content: "The Iran-Contra affair is another perfect example of how intelligence operations can completely bypass democratic oversight.",
    user_id: "user-1",
    thread_id: "thread-3",
    parent_id: "comment-5",
    vote_count: 32,
    created_at: "2025-10-18T15:30:00Z",
    updated_at: "2025-10-18T15:30:00Z",
    author: mockProfiles[0],
  },
]

export function getThreadsByCategory(categorySlug: string): Thread[] {
  const category = mockCategories.find((c) => c.slug === categorySlug)
  if (!category) return []
  return mockThreads.filter((t) => t.category_id === category.id)
}

export function getThreadById(id: string): Thread | undefined {
  return mockThreads.find((t) => t.id === id)
}

export function getCommentsByThread(threadId: string): Comment[] {
  return mockComments.filter((c) => c.thread_id === threadId)
}

export function getProfileByUsername(username: string): Profile | undefined {
  return mockProfiles.find((p) => p.username === username)
}

export function getThreadsByUser(userId: string): Thread[] {
  return mockThreads.filter((t) => t.user_id === userId)
}

export function formatRelativeTime(dateString: string, locale: "tr" | "en"): string {
  const date = new Date(dateString)
  const now = new Date()
  const diffMs = now.getTime() - date.getTime()
  const diffMinutes = Math.floor(diffMs / 60000)
  const diffHours = Math.floor(diffMs / 3600000)
  const diffDays = Math.floor(diffMs / 86400000)
  const diffWeeks = Math.floor(diffDays / 7)
  const diffMonths = Math.floor(diffDays / 30)

  if (diffMinutes < 1) return locale === "tr" ? "az once" : "just now"
  if (diffMinutes < 60) return `${diffMinutes} ${locale === "tr" ? "dk once" : "min ago"}`
  if (diffHours < 24) return `${diffHours} ${locale === "tr" ? "saat once" : "hours ago"}`
  if (diffDays < 7) return `${diffDays} ${locale === "tr" ? "gun once" : "days ago"}`
  if (diffWeeks < 4) return `${diffWeeks} ${locale === "tr" ? "hafta once" : "weeks ago"}`
  return `${diffMonths} ${locale === "tr" ? "ay once" : "months ago"}`
}
