import type { Metadata } from "next";
import Link from "next/link";
import { LegalPageLayout } from "@/components/LegalPageLayout";
import { LEGAL_OPERATOR } from "@/lib/legal/constants";

export const metadata: Metadata = {
  title: "Terms of Service | Songs2VID",
  description: "Terms and conditions for using the Songs2VID hosted service.",
};

export default function TermsPage() {
  return (
    <LegalPageLayout
      title="Terms of Service"
      description="Please read these terms carefully before using Songs2VID."
    >
      <h2>1. Agreement</h2>
      <p>
        These Terms of Service (&quot;Terms&quot;) govern your access to and use of the Songs2VID
        website and hosted cloud service (the &quot;Service&quot;) operated by{" "}
        {LEGAL_OPERATOR.legalName} (&quot;we&quot;, &quot;us&quot;). By creating an account or using
        the Service, you agree to these Terms.
      </p>
      <p>
        If you do not agree, do not use the Service. If you self-host the open-source software on
        your own infrastructure without using our hosted Service, these Terms apply only to the
        extent you use our website, support channels, or paid services we provide.
      </p>

      <h2>2. The Service</h2>
      <p>
        Songs2VID converts user-provided images and audio files into videos and can upload them to
        YouTube using your connected Google/YouTube account. Features, limits, and availability
        depend on your plan.
      </p>
      <ul>
        <li>
          <strong>Bedroom Producer (Free):</strong> 10 video credits per calendar month, 720p, MP3,
          optional Songs2VID watermark (bottom-right), one static cover image per batch; may purchase
          limited extra credits as described in Clause 8.2
        </li>
        <li>
          <strong>Independent Artist (Pro):</strong> 50 video credits per month, higher resolution and
          batch limits, API access, custom watermark/logo/typography, blurred art-track layouts with
          position controls, unique image per
          track in bulk uploads, and other features as described on our pricing page (€5/month
          unless otherwise stated at checkout)
        </li>
        <li>
          <strong>Enterprise (Record Label / Studio):</strong> custom terms as agreed in writing
        </li>
      </ul>
      <p>
        We may modify features, limits, or pricing with reasonable notice where required. The
        open-source software is provided separately under its applicable open-source license.
      </p>

      <h2>3. Eligibility and accounts</h2>
      <ul>
        <li>You must be at least 16 years old or the age required in your jurisdiction</li>
        <li>You must have a valid Google account and authorized access to the YouTube channel you connect</li>
        <li>You are responsible for maintaining the security of your account and OAuth connection</li>
        <li>You must provide accurate information and promptly update it if it changes</li>
      </ul>

      <h2>4. Your content and responsibilities</h2>
      <p>You retain ownership of content you upload. You grant us a limited license to host, process, encode, transmit, and upload your content solely to provide the Service.</p>
      <p>You represent and warrant that:</p>
      <ul>
        <li>You own or have all necessary rights to the content you upload</li>
        <li>Your content and use of the Service comply with applicable law and YouTube policies</li>
        <li>Your content does not infringe third-party rights or contain unlawful material</li>
        <li>You have configured metadata (including &quot;Made for Kids&quot; and privacy settings) accurately</li>
      </ul>
      <p>
        You are solely responsible for content published to your YouTube channel through the
        Service.
      </p>

      <h2>5. Acceptable use</h2>
      <p>You agree not to:</p>
      <ul>
        <li>Use the Service for unlawful, harmful, or abusive purposes</li>
        <li>Upload malware, attempt unauthorized access, or interfere with the Service</li>
        <li>Circumvent quotas, plan limits, or technical restrictions</li>
        <li>Resell or commercially exploit the hosted Service without authorization</li>
        <li>Use the Service in a way that violates Google, YouTube, or third-party terms</li>
      </ul>
      <p>We may suspend or terminate access for violations or risks to the Service or other users.</p>

      <h2>6. YouTube and third-party services</h2>
      <p>
        The Service integrates with Google OAuth and the YouTube Data API to sign you in, connect
        your channel, upload videos you create, and create or list playlists you request. Your use
        of those services is also subject to{" "}
        <a href="https://policies.google.com/terms" target="_blank" rel="noopener noreferrer">
          Google Terms of Service
        </a>
        ,{" "}
        <a href="https://www.youtube.com/t/terms" target="_blank" rel="noopener noreferrer">
          YouTube Terms of Service
        </a>
        ,{" "}
        <a
          href="https://developers.google.com/youtube/terms/api-services-terms-of-service"
          target="_blank"
          rel="noopener noreferrer"
        >
          YouTube API Services Terms
        </a>
        , and{" "}
        <a href="https://policies.google.com/privacy" target="_blank" rel="noopener noreferrer">
          Google&apos;s Privacy Policy
        </a>
        . We are not responsible for changes, outages, quota limits, or enforcement actions taken by
        Google or YouTube. How we handle Google user data is described in our{" "}
        <Link href="/privacy">Privacy Policy</Link>.
      </p>

      <h2>7. Open-source software</h2>
      <p>
        Portions of Songs2VID are available as open-source software. Self-hosting is permitted under
        the applicable open-source license. The hosted Service, enterprise features, managed
        infrastructure, and certain premium capabilities may require a separate commercial license
        or subscription.
      </p>

      <h2>8. Subscription, Billing &amp; Credits</h2>
      <p>
        Paid plans and credit top-ups are billed according to the pricing displayed at the time of
        purchase. Taxes may apply. Payments are processed by Stripe. Subscriptions renew
        automatically unless cancelled in accordance with our{" "}
        <Link href="/refund">Refund Policy</Link>. Failure to pay may result in downgrade or
        suspension.
      </p>
      <p>
        <strong>Credit usage order:</strong> when you create video jobs, we deduct from your current
        monthly allocation first, then from any purchased extra credits.
      </p>

      <h3>8.1 Pro plan quota and rate-limit extensions</h3>
      <p>
        Independent Artist (Pro) subscribers receive <strong>50 video credits</strong> per
        subscription month. Unused credits from prior cycles may roll over into the next cycle
        subject to the accumulation cap in Clause 8.3. Renewal and rollover occur on successful
        Stripe subscription renewal (typically aligned with your billing period).
      </p>
      <p>
        Pro subscribers may request a manual video-quota reset or temporary extension, and/or an API
        rate-limit extension, via account settings or by emailing{" "}
        <a href={`mailto:${LEGAL_OPERATOR.quotaRequestEmail}`}>
          {LEGAL_OPERATOR.quotaRequestEmail}
        </a>
        . Each Pro account is entitled to up to{" "}
        <strong>five (5) video-quota reset or extension requests per calendar year</strong> and up
        to <strong>five (5) API rate-limit extension requests per calendar year</strong>. We review
        requests in good faith and may decline requests that are abusive, repetitive without cause,
        or inconsistent with fair use. Approved requests do not increase those annual limits.
      </p>

      <h3>8.2 Free plan extra credits</h3>
      <p>
        Bedroom Producer (Free) accounts receive <strong>10 video credits</strong> per calendar
        month. Free users may purchase additional never-expiring extra credits at the price shown at
        checkout (currently <strong>€0.25 per credit</strong>), in packs of{" "}
        <strong>1 to 15 credits</strong> per purchase. On the Free plan, the extras balance may not
        exceed <strong>15 credits</strong>. After monthly and extra credits are exhausted, further
        uploads require upgrading to Pro (or waiting for the next monthly reset). Extra credits are
        available only on the Free plan purchase flow; Pro includes its monthly allocation and does
        not sell the same Free top-up packs.
      </p>

      <h3>8.3 Credit rollover &amp; accumulation cap</h3>
      <p>
        Unused credits from previous cycles may roll over, but the total accumulated balance on any
        account (remaining monthly allocation + extra credits) shall strictly not exceed{" "}
        <strong>30 credits</strong> at any given time. Upon renewal (or when applying a new monthly
        allocation), any excess above this 30-credit threshold is automatically trimmed and expires
        permanently, without entitlement to refund or compensation.
      </p>

      <h3>8.4 Pro API access</h3>
      <p>
        Independent Artist (Pro) subscribers may generate an API key in account settings to upload
        files and create batch video jobs programmatically. API access requires an active Pro
        subscription, a connected YouTube account, and compliance with the same quota, file-type, and
        resolution limits as the web interface. API keys are personal, must be kept confidential, and
        may be revoked by you or by us if misused. We may apply rate limits and suspend API access
        for abuse, security incidents, or plan downgrades. If your subscription ends or you are
        moved to the Free plan, API keys and Pro-only API access are revoked or disabled.
      </p>

      <h2>9. Availability and support</h2>
      <p>
        We strive for high availability but do not guarantee uninterrupted access. Maintenance,
        updates, and outages may occur. Support levels depend on your plan. Self-hosted DIY
        deployments without a paid setup are community-supported unless otherwise agreed in
        writing.
      </p>

      <h2>10. Disclaimer of warranties</h2>
      <p>
        THE SERVICE IS PROVIDED &quot;AS IS&quot; AND &quot;AS AVAILABLE&quot; TO THE MAXIMUM EXTENT
        PERMITTED BY LAW. WE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. WE DO NOT WARRANT THAT ENCODING,
        UPLOADS, OR METADATA TRANSFER WILL BE ERROR-FREE OR UNINTERRUPTED.
      </p>

      <h2>11. Limitation of liability</h2>
      <p>
        TO THE MAXIMUM EXTENT PERMITTED BY LAW, WE SHALL NOT BE LIABLE FOR INDIRECT, INCIDENTAL,
        SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS, REVENUE, DATA, OR
        GOODWILL. OUR TOTAL LIABILITY FOR ANY CLAIM ARISING OUT OF THESE TERMS OR THE SERVICE IS
        LIMITED TO THE AMOUNT YOU PAID US IN THE TWELVE (12) MONTHS BEFORE THE EVENT GIVING RISE TO
        THE CLAIM, OR EUR 100 IF YOU USE THE FREE PLAN ONLY.
      </p>
      <p>
        Some jurisdictions do not allow certain limitations, so some of the above may not apply to
        you.
      </p>

      <h2>12. Indemnification</h2>
      <p>
        You agree to indemnify and hold us harmless from claims arising out of your content, your
        use of the Service, or your violation of these Terms or applicable law.
      </p>

      <h2>13. Termination and account deletion</h2>
      <p>
        You may stop using the Service at any time. You may cancel a paid subscription (see our{" "}
        <Link href="/refund">Refund Policy</Link>) without deleting your account. To permanently
        delete your account and associated active data, use the account deletion control in{" "}
        <strong>Dashboard → Settings</strong> or contact{" "}
        <a href={`mailto:${LEGAL_OPERATOR.email}`}>{LEGAL_OPERATOR.email}</a>. We may suspend or
        terminate your access if you breach these Terms, create risk or legal exposure, or where
        required by law. Upon termination or deletion, your right to use the hosted Service ends.
        Provisions that by nature should survive will survive. Deletion is subject to legal
        retention obligations described in our <Link href="/privacy">Privacy Policy</Link>.
      </p>

      <h2>14. Governing law</h2>
      <p>
        These Terms are governed by the laws of Hungary, excluding conflict
        of law rules. Courts in Hungary shall have exclusive jurisdiction unless
        mandatory consumer protection laws in your country provide otherwise.
      </p>

      <h2>15. Changes</h2>
      <p>
        We may update these Terms from time to time. Continued use after changes become effective
        constitutes acceptance of the revised Terms, where permitted by law.
      </p>

      <h2>16. Contact</h2>
      <p>
        Questions about these Terms:{" "}
        <a href={`mailto:${LEGAL_OPERATOR.email}`}>{LEGAL_OPERATOR.email}</a>
      </p>
    </LegalPageLayout>
  );
}
