import { Metadata } from 'next'

interface SEOSettings {
  metaTitle?: string
  metaDescription?: string
  metaKeywords?: string
  ogImage?: string
  siteName?: string
  siteUrl?: string
}

export function generateSEOMetadata(settings: SEOSettings, defaultTitle?: string): Metadata {
  const title = settings.metaTitle || defaultTitle || 'Polres Wonosobo - Sistem Pelayanan Digital'
  const description = settings.metaDescription || 'Layanan pengajuan dokumen kepolisian secara online yang mudah, cepat, dan terpercaya'
  const keywords = settings.metaKeywords || 'polres wonosobo, pelayanan polisi, pengajuan dokumen, kepolisian'
  const ogImage = settings.ogImage || '/og-image.jpg'
  const siteName = settings.siteName || 'Polres Wonosobo'
  const siteUrl = settings.siteUrl || 'https://polres-wonosobo.example.com'

  return {
    title,
    description,
    keywords,
    authors: [{ name: siteName }],
    creator: siteName,
    publisher: siteName,
    metadataBase: new URL(siteUrl),
    openGraph: {
      title,
      description,
      type: 'website',
      locale: 'id_ID',
      url: siteUrl,
      siteName,
      images: [
        {
          url: ogImage,
          width: 1200,
          height: 630,
          alt: title,
        },
      ],
    },
    twitter: {
      card: 'summary_large_image',
      title,
      description,
      images: [ogImage],
      creator: '@polreswonosobo',
    },
    robots: {
      index: true,
      follow: true,
      googleBot: {
        index: true,
        follow: true,
        'max-video-preview': -1,
        'max-image-preview': 'large',
        'max-snippet': -1,
      },
    },
    verification: {
      google: 'your-google-verification-code',
      yandex: 'your-yandex-verification-code',
    },
  }
}

export function generateJsonLd(settings: SEOSettings, pageType: string = 'website') {
  const title = settings.metaTitle || 'Polres Wonosobo - Sistem Pelayanan Digital'
  const description = settings.metaDescription || 'Layanan pengajuan dokumen kepolisian secara online yang mudah, cepat, dan terpercaya'
  const siteUrl = settings.siteUrl || 'https://polres-wonosobo.example.com'
  const ogImage = settings.ogImage || '/og-image.jpg'

  const baseJsonLd = {
    '@context': 'https://schema.org',
    '@type': pageType === 'organization' ? 'GovernmentOrganization' : 'WebSite',
    name: settings.siteName || 'Polres Wonosobo',
    description,
    url: siteUrl,
    image: ogImage,
    sameAs: [
      'https://www.facebook.com/polreswonosobo',
      'https://twitter.com/polreswonosobo',
      'https://www.instagram.com/polreswonosobo',
    ],
  }

  if (pageType === 'organization') {
    return {
      ...baseJsonLd,
      address: {
        '@type': 'PostalAddress',
        streetAddress: 'Jl. Pahlawan No. 15, Wonosobo',
        addressLocality: 'Wonosobo',
        addressRegion: 'Jawa Tengah',
        postalCode: '56311',
        addressCountry: 'ID',
      },
      telephone: '(0286) 321001',
      email: 'polreswonosobo@polri.go.id',
      openingHours: 'Mo-Fr 08:00-16:00',
    }
  }

  return baseJsonLd
}