// JSON-LD Schema generators for structured data

export const SITE_INFO = {
  name: "Trains of Rajbari",
  alternateName: "রাজবাড়ীর ট্রেন",
  url: "https://trainsofrajbari.com",
  description:
    "Complete railway guide for Rajbari district with train schedules, station info, and real-time updates",
  logo: "https://trainsofrajbari.com/logo.png",
  logoCircle: "https://trainsofrajbari.com/logo-circle.png",
  foundingDate: "2023",
  sameAs: [
    "https://www.facebook.com/TrainSOfRajbari/",
    "https://www.youtube.com/@TrainSOfRajbari",
    "https://www.facebook.com/groups/trainsofrajbari",
  ],
  contactPoint: {
    type: "Customer Support",
    areaServed: "BD",
    availableLanguage: ["English", "Bengali"],
  },
};

// Organization schema
export const getOrganizationSchema = () => ({
  "@context": "https://schema.org",
  "@type": "Organization",
  name: SITE_INFO.name,
  alternateName: SITE_INFO.alternateName,
  url: SITE_INFO.url,
  logo: SITE_INFO.logo,
  foundingDate: SITE_INFO.foundingDate,
  description: SITE_INFO.description,
  sameAs: SITE_INFO.sameAs,
  contactPoint: {
    "@type": "ContactPoint",
    contactType: SITE_INFO.contactPoint.type,
    areaServed: SITE_INFO.contactPoint.areaServed,
    availableLanguage: SITE_INFO.contactPoint.availableLanguage,
  },
});

// WebSite schema with SearchAction
export const getWebSiteSchema = () => ({
  "@context": "https://schema.org",
  "@type": "WebSite",
  name: SITE_INFO.name,
  alternateName: SITE_INFO.alternateName,
  url: SITE_INFO.url,
  description: SITE_INFO.description,
  inLanguage: ["en-US", "bn-BD"],
  publisher: {
    "@type": "Organization",
    name: SITE_INFO.name,
    logo: {
      "@type": "ImageObject",
      url: SITE_INFO.logo,
    },
    sameAs: SITE_INFO.sameAs,
  },
  potentialAction: {
    "@type": "SearchAction",
    target: `${SITE_INFO.url}/schedules?station={search_term_string}`,
    "query-input": "required name=search_term_string",
  },
});

// WebPage schema
export const getWebPageSchema = ({
  title,
  description,
  url,
  image,
  dateModified,
}) => ({
  "@context": "https://schema.org",
  "@type": "WebPage",
  name: title,
  description: description,
  url: url,
  image: image || SITE_INFO.logo,
  dateModified: dateModified || new Date().toISOString().split("T")[0],
  inLanguage: ["en-US", "bn-BD"],
  isPartOf: {
    "@type": "WebSite",
    name: SITE_INFO.name,
    url: SITE_INFO.url,
  },
  publisher: {
    "@type": "Organization",
    name: SITE_INFO.name,
    logo: {
      "@type": "ImageObject",
      url: SITE_INFO.logo,
    },
  },
});

// Train Route schema (for Dhaka-Rajbari type pages)
export const getTrainRouteSchema = ({
  fromStation,
  toStation,
  banglaFrom,
  banglaTo,
  distance,
  // eslint-disable-next-line no-unused-vars
  duration,
  // eslint-disable-next-line no-unused-vars
  availableTrains,
  // eslint-disable-next-line no-unused-vars
  url,
}) => ({
  "@context": "https://schema.org",
  "@type": "TravelAction",
  name: `${fromStation} to ${toStation} Train`,
  alternateName: `${banglaFrom} থেকে ${banglaTo} ট্রেন`,
  fromLocation: {
    "@type": "TrainStation",
    name: `${fromStation} Railway Station`,
    address: {
      "@type": "PostalAddress",
      addressCountry: "BD",
      addressRegion:
        fromStation.toLowerCase() === "dhaka" ? "Dhaka" : "Rajbari",
    },
  },
  toLocation: {
    "@type": "TrainStation",
    name: `${toStation} Railway Station`,
    address: {
      "@type": "PostalAddress",
      addressCountry: "BD",
      addressRegion: toStation.toLowerCase() === "dhaka" ? "Dhaka" : "Rajbari",
    },
  },
  distance: {
    "@type": "Distance",
    name: distance,
  },
  provider: {
    "@type": "Organization",
    name: "Bangladesh Railway",
    url: "https://railway.gov.bd",
  },
});

// FAQPage schema for route pages
export const getRouteFAQSchema = ({
  fromStation,
  toStation,
  availableTrains,
  duration,
  distance,
}) => ({
  "@context": "https://schema.org",
  "@type": "FAQPage",
  mainEntity: [
    {
      "@type": "Question",
      name: `How many trains run from ${fromStation} to ${toStation}?`,
      acceptedAnswer: {
        "@type": "Answer",
        text: `There are ${availableTrains} trains operating daily from ${fromStation} to ${toStation}. Popular trains include Sundarban Express, Benapole Express, Madhumati Express, and Tungipara Express.`,
      },
    },
    {
      "@type": "Question",
      name: `What is the distance from ${fromStation} to ${toStation} by train?`,
      acceptedAnswer: {
        "@type": "Answer",
        text: `The distance from ${fromStation} to ${toStation} by train is approximately ${distance}. The journey takes around ${duration} depending on the train type.`,
      },
    },
    {
      "@type": "Question",
      name: `How can I book ${fromStation} to ${toStation} train tickets?`,
      acceptedAnswer: {
        "@type": "Answer",
        text: `You can book tickets online through the official Bangladesh Railway e-ticketing website (eticket.railway.gov.bd) or the Rail Sheba mobile app. Tickets are also available at ${fromStation} Railway Station counter.`,
      },
    },
    {
      "@type": "Question",
      name: `What is the ticket price from ${fromStation} to ${toStation}?`,
      acceptedAnswer: {
        "@type": "Answer",
        text: `Ticket prices vary by class and train type. Shovan class starts from around ৳120-150, Snigdha class around ৳250-300, and AC Chair around ৳400-500. Check the official e-ticketing portal for exact fares.`,
      },
    },
    {
      "@type": "Question",
      name: `What is the best train from ${fromStation} to ${toStation}?`,
      acceptedAnswer: {
        "@type": "Answer",
        text: `The Sundarban Express is the most popular intercity train on this route, known for its comfort and punctuality. Benapole Express and Madhumati Express are also excellent options for comfortable travel.`,
      },
    },
  ],
});

// TrainStation schema
export const getTrainStationSchema = ({
  stationName,
  // eslint-disable-next-line no-unused-vars
  stationId,
  description,
  image,
}) => ({
  "@context": "https://schema.org",
  "@type": "TrainStation",
  name: stationName,
  description: description,
  image: image || SITE_INFO.logo,
  address: {
    "@type": "PostalAddress",
    addressLocality: stationName
      .replace(" Railway Station", "")
      .replace(" Junction", ""),
    addressRegion: "Rajbari District",
    addressCountry: "BD",
  },
  geo: {
    "@type": "GeoCoordinates",
    addressCountry: "BD",
  },
  isAccessibleForFree: true,
  publicAccess: true,
});

// Train schedule table schema
export const getTrainScheduleSchema = (scheduleItems) => ({
  "@context": "https://schema.org",
  "@type": "ItemList",
  name: "Train Schedule",
  description: "Complete train schedule with departure times and routes",
  numberOfItems: scheduleItems.length,
  itemListElement: scheduleItems.slice(0, 10).map((item, index) => ({
    "@type": "ListItem",
    position: index + 1,
    item: {
      "@type": "Trip",
      name: item.name,
      description: `${item.name} - ${item.route}`,
      departureTime: item.departure,
      provider: {
        "@type": "Organization",
        name: "Bangladesh Railway",
      },
    },
  })),
});

// Article schema for blog posts
export const getArticleSchema = ({
  title,
  description,
  author,
  datePublished,
  image,
  url,
}) => ({
  "@context": "https://schema.org",
  "@type": "Article",
  headline: title,
  description: description,
  author: {
    "@type": "Person",
    name: author || "Trains of Rajbari",
  },
  datePublished: datePublished,
  dateModified: datePublished,
  image: image || SITE_INFO.logo,
  publisher: {
    "@type": "Organization",
    name: SITE_INFO.name,
    logo: {
      "@type": "ImageObject",
      url: SITE_INFO.logo,
    },
  },
  mainEntityOfPage: {
    "@type": "WebPage",
    "@id": url,
  },
});

// BlogPosting list schema
export const getBlogListSchema = (blogs) => ({
  "@context": "https://schema.org",
  "@type": "CollectionPage",
  name: "Railway Updates & Stories",
  description:
    "Latest news, announcements and stories from Rajbari's railway tracks",
  url: `${SITE_INFO.url}/blogs`,
  mainEntity: {
    "@type": "ItemList",
    itemListElement: blogs.map((blog, index) => ({
      "@type": "ListItem",
      position: index + 1,
      item: {
        "@type": "BlogPosting",
        headline: blog.title,
        description: blog.excerpt,
        datePublished: blog.date,
        author: {
          "@type": "Person",
          name: blog.author,
        },
        url: `${SITE_INFO.url}/blog/${blog.slug}`,
      },
    })),
  },
});

// About page schema (Person/Team)
export const getAboutPageSchema = (teamMembers) => ({
  "@context": "https://schema.org",
  "@type": "AboutPage",
  name: "About Trains of Rajbari",
  description:
    "Learn about the Trains of Rajbari community, our mission, and the team behind the platform",
  url: `${SITE_INFO.url}/about`,
  mainEntity: {
    "@type": "Organization",
    name: SITE_INFO.name,
    foundingDate: SITE_INFO.foundingDate,
    description: SITE_INFO.description,
    sameAs: SITE_INFO.sameAs,
    member: teamMembers.map((member) => ({
      "@type": "Person",
      name: member.name,
      jobTitle: member.role,
      description: member.bio,
    })),
  },
});

// LocalBusiness schema for train-related services page
export const getLocalBusinessSchema = () => ({
  "@context": "https://schema.org",
  "@type": "LocalBusiness",
  name: SITE_INFO.name,
  description: SITE_INFO.description,
  url: SITE_INFO.url,
  logo: SITE_INFO.logo,
  image: SITE_INFO.logo,
  address: {
    "@type": "PostalAddress",
    addressLocality: "Rajbari",
    addressRegion: "Rajbari District",
    addressCountry: "BD",
  },
  sameAs: SITE_INFO.sameAs,
  priceRange: "Free",
});

// Helper to generate multiple schemas for a page
export const generateSchemas = (schemas) => {
  return schemas.map((schema) => JSON.stringify(schema)).join("\n");
};
