import { getSeoMetadata } from "@/lib/seo";

export const dynamic = "force-dynamic";
export const revalidate = 0;

export async function generateMetadata() {
  const seo = await getSeoMetadata("/platform/sms/otp-authentication", {
    title: "OTP Authentication API | Instant SMS & WhatsApp OTP Verification | TextSpeed",
    description: "Secure your app with TextSpeed's OTP Authentication API. Sub-5-second SMS, WhatsApp & Voice OBD delivery, built-in verification, retry logic, and fraud protection — DLT compliant.",
    keywords: "otp authentication, otp api, sms otp, otp verification, one time password, otp service",
  });

  return {
    ...seo,
    alternates: {
      canonical: "https://textspeed.in/platform/sms/otp-authentication",
    },
    openGraph: {
      title: seo.title,
      description: seo.description,
      type: "website",
      url: "https://textspeed.in/platform/sms/otp-authentication",
    },
    twitter: {
      card: "summary_large_image",
      title: seo.title,
      description: seo.description,
    },
  };
}

export default function OtpAuthenticationLayout({ children }) {
  const jsonLd = {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "BreadcrumbList",
        "@id": "https://textspeed.in/platform/sms/otp-authentication#breadcrumb",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "Home",
            "item": "https://textspeed.in"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Platform",
            "item": "https://textspeed.in/platform/sms/promotional-sms"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "SMS",
            "item": "https://textspeed.in/platform/sms/promotional-sms"
          },
          {
            "@type": "ListItem",
            "position": 4,
            "name": "OTP Authentication",
            "item": "https://textspeed.in/platform/sms/otp-authentication"
          }
        ]
      },
      {
        "@type": "Service",
        "@id": "https://textspeed.in/platform/sms/otp-authentication#service",
        "name": "OTP Verification & Authentication Service",
        "provider": {
          "@type": "Organization",
          "name": "TextSpeed",
          "url": "https://textspeed.in"
        },
        "description": "Secure API for generating, sending, and verifying one-time passwords via SMS, WhatsApp, and voice with automatic fallbacks.",
        "areaServed": "IN"
      },
      {
        "@type": "FAQPage",
        "@id": "https://textspeed.in/platform/sms/otp-authentication#faq",
        "mainEntity": [
          {
            "@type": "Question",
            "name": "What happens if the user doesn't receive the OTP?",
            "acceptedAnswer": {
              "@type": "Answer",
              "text": "You can configure automatic fallback to WhatsApp or a Voice call after a set delay, so delivery never fully depends on one channel."
            }
          },
          {
            "@type": "Question",
            "name": "How long is an OTP valid?",
            "acceptedAnswer": {
              "@type": "Answer",
              "text": "Configurable per flow — default is 5 minutes, adjustable from your dashboard or the API request."
            }
          },
          {
            "@type": "Question",
            "name": "Does TextSpeed store the OTP code?",
            "acceptedAnswer": {
              "@type": "Answer",
              "text": "Codes are handled transiently for verification and are never written to plaintext logs."
            }
          },
          {
            "@type": "Question",
            "name": "Can I limit resend attempts?",
            "acceptedAnswer": {
              "@type": "Answer",
              "text": "Yes, resend cooldowns and max daily attempts per number are configurable to prevent abuse."
            }
          },
          {
            "@type": "Question",
            "name": "Do I need DLT registration for OTP templates?",
            "acceptedAnswer": {
              "@type": "Answer",
              "text": "Yes, same as any transactional SMS. TextSpeed pre-registers a compliant OTP template so you can go live immediately."
            }
          }
        ]
      }
    ]
  };

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
      />
      {children}
    </>
  );
}
