import { defineOrganization } from "nuxt-schema-org/schema";
import type { Review, Settings } from "~/types/Contact";

export const useOrganizationSchema = (
  settings = {} as Settings,
  reviews: Review[] = [],
  t: any,
) => {
  const localPath = useLocalePath();

  const socialLinks = [
    settings?.facebook_link,
    settings?.instagram_link,
    settings?.tiktok_link,
    settings?.X_link,
    settings?.linkedIn_link,
    settings?.snapchat_link,
    settings?.youtube_link,
  ].filter(Boolean);

  //Static Contact Points
  const contactPoints = [
    {
      "@type": "ContactPoint",
      telephone: "+9661000025705",
      contactType: "customer service",
      email: "info@webstdy.com",
      areaServed: "Worldwide",
      availableLanguage: ["en", "ar"],
      additionalProperty: {
        "@type": "PropertyValue",
        name: "WhatsApp",
        value: "+9661000025705",
      },
    },
  ];

  //Static Addresses
  const mainAddress = {
    "@type": "PostalAddress",
    streetAddress: "38 شارع الثورة، الدقي، الجيزة",
    addressLocality: "الجيزة",
    postalCode: "12345",
    addressCountry: "EG",
  };

  const additionalAddresses = [
    {
      "@type": "PostalAddress",
      streetAddress: "4064 مركز الهدلق، مكتب 26، طريق أنس بن مالك",
      addressLocality: "الرياض",
      postalCode: "12345",
      addressCountry: "SA",
    },
  ];

  const aggregateRating = {
    "@type": "AggregateRating",
    ratingValue: "4.9",
    bestRating: "5",
    worstRating: "1",
    reviewCount: "57",
  };

  useSchemaOrg([
    // Main Organization Schema
    defineOrganization({
      name: "WebSTDY",
      legalName: "Webstdy LLC.",
      url: localPath("https://webstdy.com/"),
      logo:
        settings?.light_logo ||
        "https://webstdy.com/web/img/2022/new-share-image.png",
      slogan: "Learn Today, Lead Tomorrow",
      description: computed(() => t("homeSeo.description")),
      keywords: [
        "web development",
        "programming",
        "design",
        "data science",
        "AI",
        "e-learning",
      ],

      knowsAbout: [
        "software development",
        "e-learning platforms",
        "web development",
        "programming",
      ],

      knowsLanguage: ["en", "ar"],
      foundingDate: "2017-07-07",

      founder: {
        "@type": "Person",
        name: "Mahmoud Nabil",
      },

      contactPoint: contactPoints,
      address: mainAddress,

      ...(socialLinks.length > 0 && { sameAs: socialLinks }),
    }),

    // LocalBusiness Schema for Star Ratings
    {
      "@type": ["LocalBusiness", "ProfessionalService"],
      "@id": localPath("/#business"),
      name: "WebSTDY - Software Development Company",

      description:
        "Professional software development agency specializing in web applications, mobile apps, and custom software solutions",

      url: localPath("https://webstdy.com/"),

      image:
        settings?.light_logo ||
        "https://webstdy.com/web/img/2022/new-share-image.png",

      telephone: "+9661000025705",
      email: "info@webstdy.com",

      address: mainAddress,

      // Additional locations
      ...(additionalAddresses.length > 0 && {
        branchOf: {
          "@type": "Organization",
          name: "WebSTDY",
        },
      }),

      // Price range for services
      priceRange: "$$$",

      // Services offered
      hasOfferCatalog: {
        "@type": "OfferCatalog",
        name: "Software Development Services",
        itemListElement: [
          {
            "@type": "Offer",
            itemOffered: {
              "@type": "Service",
              name: "Web Application Development",
              description: "Custom web application development services",
            },
          },
          {
            "@type": "Offer",
            itemOffered: {
              "@type": "Service",
              name: "Mobile App Development",
              description: "iOS and Android mobile application development",
            },
          },
          {
            "@type": "Offer",
            itemOffered: {
              "@type": "Service",
              name: "E-Learning Platform Development",
              description:
                "Custom e-learning and educational platform solutions",
            },
          },
        ],
      },

      // Service area
      areaServed: [
        {
          "@type": "Country",
          name: "Egypt",
        },
        {
          "@type": "Country",
          name: "Saudi Arabia",
        },
        {
          "@type": "AdministrativeArea",
          name: "Worldwide",
        },
      ],

      // Opening hours
      openingHoursSpecification: {
        "@type": "OpeningHoursSpecification",
        dayOfWeek: ["Monday", "Tuesday", "Wednesday", "Thursday", "Sunday"],
        opens: "10:00",
        closes: "20:00",
      },

      aggregateRating,

      // Individual reviews
      review: reviews.map((review) => ({
        "@type": "Review",
        author: {
          "@type": "Person",
          name: review.author,
        },
        reviewRating: {
          "@type": "Rating",
          ratingValue: review.rating.toString(),
          bestRating: "5",
          worstRating: "1",
        },
        reviewBody: review.body,
        datePublished: "2025-11-10",
      })),

      ...(socialLinks.length > 0 && { sameAs: socialLinks }),
    },
  ]);
};
