import { testClient } from "hono/testing";
import { describe, expect, it } from "vitest";
import { createConfig } from "../../config.js";
import { MiddlewareManager } from "../../middlewares/middleware.js";
import { getMainRouter } from "../../routers/index.js";

describe("Maybe Authenticated Router", () => {
  // In test mode, createConfig() reads from .env.test
  const config = createConfig();
  MiddlewareManager.initialize(config);
  const app = getMainRouter(config);
  // biome-ignore lint/suspicious/noExplicitAny: testClient requires any for dynamic route access
  const client = testClient(app) as any;

  it("should allow unauthenticated requests", async () => {
    const res = await client["v1"].book.slot.$post({
      json: {
        owner_short_id: "abc123",
        event_type_standard_name: "consultation",
        event_details: {
          start_date: "2025-01-15",
          start_time: "10:00",
          end_time: "11:00",
        },
        user_details: {
          name: "Test User",
          email: "test@example.com",
        },
      },
    });

    // Should process but fail due to invalid data in test environment
    expect(res.status >= 400).toBeTruthy();
  });

  it("should handle authenticated requests", async () => {
    const token = "this-is-a-very-clean-token";
    const res = await client["v1"].book.slot.$post(
      {
        json: {
          owner_short_id: "abc123",
          event_type_standard_name: "consultation",
          event_details: {
            start_date: "2025-01-15",
            start_time: "10:00",
            end_time: "11:00",
          },
          user_details: {
            name: "Test User",
            email: "test@example.com",
          },
        },
      },
      {
        headers: {
          Authorization: `Bearer ${token}`,
          "Content-Type": "application/json",
        },
      }
    );

    expect(res.status >= 400).toBeTruthy();
  });
});
