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

import {
  FacebookIdentityResponseSchema,
  LoginRequestSchema,
  TopUpHandoffResponseSchema,
} from "@/data/schemas/auth";
import { UserSchema } from "@/data/schemas/user/user";

describe("facebook identity schema models", () => {
  it("parses facebook identity binding responses", () => {
    const response = FacebookIdentityResponseSchema.parse({
      fbAsid: "asid-1",
      fbPsid: "psid-1",
      facebookBinding: {
        conflicts: [],
        bound: [{ field: "psid" }],
      },
    });

    expect(response).toMatchObject({
      fbAsid: "asid-1",
      fbPsid: "psid-1",
      facebookBinding: {
        conflicts: [],
        bound: [{ field: "psid" }],
      },
    });
  });

  it("keeps psid in request serialization without a public field declaration", () => {
    const request = LoginRequestSchema.parse({
      email: "user@example.com",
      password: "password",
      platform: "web",
      guestId: "",
      psid: "psid-1",
    });

    expect(request).toMatchObject({ psid: "psid-1" });
  });

  it("parses a formal Messenger top-up handoff session", () => {
    expect(
      TopUpHandoffResponseSchema.parse({
        token: "login-token",
        refreshToken: "refresh-token",
        loginStatus: "facebookMessenger",
        merged: false,
        user: { id: "user-1", username: "Messenger User" },
      }),
    ).toMatchObject({
      loginStatus: "facebookMessenger",
      user: { id: "user-1" },
    });
  });

  it("accepts facebook identity fields in user schema", () => {
    expect(
      UserSchema.parse({
        id: "user-1",
        username: "Elio",
        fbAsid: "asid-1",
        fbPsid: "psid-1",
      }),
    ).toMatchObject({
      fbAsid: "asid-1",
      fbPsid: "psid-1",
    });
  });
});
