import { describe, expect, it } from "vitest";

import {
  PrivateZonePostUnlockResponseSchema,
  PrivateZonePostsResponseSchema,
} from "@/data/schemas/private-zone";

const post = {
  postId: "11111111-1111-1111-1111-111111111111",
  characterId: "maya-tan",
  caption: "Only for you.",
  posterUrl: "https://storage.example/poster.jpg?token=short",
  mediaType: "video",
  videoUrl: null,
  videoMimeType: "video/mp4",
  videoSizeBytes: 1024,
  durationSeconds: 18,
  unlockCostCredits: 100,
  currency: "credits",
  locked: true,
  unlocked: false,
  availableForNewUnlock: true,
  publishedAt: "2026-07-24T10:00:00+00:00",
};

describe("Private Zone video post schema", () => {
  it("parses a locked post without inventing a video URL", () => {
    const response = PrivateZonePostsResponseSchema.parse({
      characterId: "maya-tan",
      items: [post],
      nextCursor: null,
      hasMore: false,
      creditBalance: 250,
      currency: "credits",
    });

    expect(response.items[0].videoUrl).toBeNull();
    expect(response.items[0].posterUrl).toContain("poster.jpg");
    expect(response.items[0].unlockCostCredits).toBe(100);
  });

  it("parses cost changes and insufficient-credit details", () => {
    const changed = PrivateZonePostUnlockResponseSchema.parse({
      postId: post.postId,
      reason: "cost_changed",
      unlocked: false,
      creditsCharged: 0,
      requiredCredits: 150,
      creditBalance: 250,
      post: { ...post, unlockCostCredits: 150 },
    });
    const insufficient = PrivateZonePostUnlockResponseSchema.parse({
      postId: post.postId,
      reason: "insufficient_credits",
      unlocked: false,
      creditsCharged: 0,
      requiredCredits: 100,
      currentCredits: 40,
      shortfallCredits: 60,
      creditBalance: 40,
      post,
    });

    expect(changed.post?.unlockCostCredits).toBe(150);
    expect(insufficient.shortfallCredits).toBe(60);
  });
});
