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

import { UserEntitlements } from "@/data/dto/user";
import { User } from "@/data/dto/user/user";

describe("User", () => {
  it("parses the latest backend user payload", () => {
    const user = User.fromJson({
      id: "d7bb2b3d-e9c5-474c-85fe-f503048f30dd",
      username: "guest_bbc90a38",
      email: "device_bbc90a38b996187348f54cf2cb0b789e@guest.local",
      platform: "web",
      country: "Hong Kong",
      countryCode: "HK",
      intimacy: 0,
      dolBalance: 0,
      personalityTraits: {
        caring: 0.5,
        playful: 0.5,
        serious: 0.5,
        cheerful: 0.5,
        romantic: 0.5,
      },
      preferredLanguage: "zh",
      createdAt: "2026-06-12T08:08:27.378706+00:00",
      lastMessageAt: "2026-06-24T11:00:23.156561+00:00",
    });

    expect(user.toJson()).toEqual({
      id: "d7bb2b3d-e9c5-474c-85fe-f503048f30dd",
      username: "guest_bbc90a38",
      email: "device_bbc90a38b996187348f54cf2cb0b789e@guest.local",
      platform: "web",
      country: "Hong Kong",
      countryCode: "HK",
      intimacy: 0,
      dolBalance: 0,
      personalityTraits: {
        caring: 0.5,
        playful: 0.5,
        serious: 0.5,
        cheerful: 0.5,
        romantic: 0.5,
      },
      preferredLanguage: "zh",
      createdAt: "2026-06-12T08:08:27.378706+00:00",
      lastMessageAt: "2026-06-24T11:00:23.156561+00:00",
    });
  });

  it("parses the latest backend entitlements payload", () => {
    const entitlements = UserEntitlements.fromJson({
      userId: "user-1",
      isGuest: false,
      isVip: true,
      vipExpiresAt: "2026-07-26T00:00:00+00:00",
      creditBalance: 120,
      dolBalance: 120,
      policy: {
        membershipState: "vip",
        nonVipEntitlementsShared: true,
        guestSameAsLoggedInNonVip: true,
        refreshAfterPayment: "GET /api/user/entitlements",
      },
      costs: {
        normal_message: 2,
        private_message: 10,
        voice_message: 20,
        photo: 40,
        voice_call_minute: 50,
        private_album_10: 300,
        private_album_20: 600,
      },
      quotas: {
        normalChatFreeDaily: 30,
        privateUnlockFreeDaily: 1,
        voiceMessageFreeDaily: 0,
        photoFreeDaily: 0,
      },
      historyUnlock: {
        enabled: true,
        order: "oldest_first",
        chargeMode: "highest_cost_per_locked_message",
        insufficientBalanceBehavior: "no_deduction",
        costs: {
          private_message: 10,
          voice_message: 20,
          photo: 40,
        },
      },
    });

    expect(entitlements.isVip).toBe(true);
    expect(entitlements.creditBalance).toBe(120);
    expect(entitlements.historyUnlock.costs.photo).toBe(40);
  });
});
