import { notFound } from "next/navigation";

import { VideoGuideView } from "@/components/domains/video-guides";
import { VideoGuideSchema } from "@/entities/dashboard/types";
import { http } from "@/shared/api/httpClient";
import { API_ROUTES } from "@/shared/constants/api-routes";

// Force dynamic to always get fresh data
export const dynamic = "force-dynamic";

export default async function VideoGuidePage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;

  // Get specific video guide data from new API
  const response = await http.get<{ status: string; data: typeof VideoGuideSchema._type }>(
    API_ROUTES.videoGuide(id),
    {
      cache: "no-store",
    }
  );

  const videoGuide = response.data;

  if (!videoGuide || !videoGuide.isPurchased) {
    notFound();
  }

  return (
    <VideoGuideView
      id={videoGuide.id}
      name={videoGuide.name}
      description={videoGuide.description}
      videoLinkHLS={videoGuide.videoLinkHLS}
      videoLinkDASH={videoGuide.videoLinkDASH}
      contentUrl={videoGuide.contentUrl}
    />
  );
}
