import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

// src/test-utils/mocks/handlers.ts
var API_BASE = "http://localhost:5170/api";
var SUPABASE_BASE = "https://eoavcmtocongsqzwxgdp.supabase.co/rest/v1";
var handlers = [
  http.post(`${API_BASE}/organizations`, async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: "550e8400-e29b-41d4-a716-446655440000",
      name: body.name,
      status: "active",
      is_test: false,
      created_at: (/* @__PURE__ */ new Date()).toISOString(),
      updated_at: (/* @__PURE__ */ new Date()).toISOString(),
      metadata: null
    });
  }),
  http.put(`${API_BASE}/organizations/:id`, async ({ request, params }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: params.id,
      name: body.name,
      workos_org_id: "wos_123",
      status: "active",
      is_test: false,
      created_at: (/* @__PURE__ */ new Date()).toISOString(),
      updated_at: (/* @__PURE__ */ new Date()).toISOString()
    });
  }),
  http.post(`${API_BASE}/users`, async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: "user-123",
      email: body.email,
      first_name: body.first_name ?? null,
      last_name: body.last_name ?? null,
      is_platform_admin: body.is_platform_admin ?? false,
      is_active: true,
      workos_user_id: "wos_user_123",
      created_at: (/* @__PURE__ */ new Date()).toISOString(),
      updated_at: (/* @__PURE__ */ new Date()).toISOString()
    });
  }),
  http.put(`${API_BASE}/users/:workosUserId`, async ({ request, params }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: "user-123",
      email: "test@example.com",
      first_name: body.firstName ?? null,
      last_name: body.lastName ?? null,
      is_platform_admin: false,
      is_active: true,
      workos_user_id: params.workosUserId,
      created_at: (/* @__PURE__ */ new Date()).toISOString(),
      updated_at: (/* @__PURE__ */ new Date()).toISOString()
    });
  }),
  http.delete(`${API_BASE}/users/:workosUserId`, () => HttpResponse.json({ success: true })),
  http.get(
    `${SUPABASE_BASE}/users`,
    () => HttpResponse.json([
      {
        id: "user-123",
        email: "test@example.com",
        first_name: "Updated",
        last_name: "User",
        is_platform_admin: false,
        is_active: true,
        workos_user_id: "wos_user_123",
        created_at: (/* @__PURE__ */ new Date()).toISOString(),
        updated_at: (/* @__PURE__ */ new Date()).toISOString(),
        last_login_at: null,
        org_memberships: []
      }
    ])
  ),
  http.patch(`${SUPABASE_BASE}/users`, () => HttpResponse.json([])),
  http.post(`${API_BASE}/api-keys`, async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: "key-123",
      name: body.name,
      key: "sk_test_1234567890abcdef",
      message: "API key created successfully"
    });
  }),
  http.get(`${API_BASE}/api-keys`, () => HttpResponse.json({ keys: [] })),
  http.delete(`${API_BASE}/api-keys/:id`, () => HttpResponse.json({ success: true })),
  http.post(`${API_BASE}/credentials`, async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({ id: "cred-123", name: body.name });
  }),
  http.get(`${API_BASE}/credentials`, () => HttpResponse.json({ credentials: [] })),
  http.delete(`${API_BASE}/credentials/:id`, () => HttpResponse.json({ success: true })),
  http.post(`${API_BASE}/invitations`, async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({
      id: "inv-123",
      email: body.email,
      role_slug: body.roleSlug,
      organization_id: body.organizationId,
      invitation_state: "pending",
      created_at: (/* @__PURE__ */ new Date()).toISOString(),
      expires_at: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
    });
  }),
  http.delete(`${API_BASE}/invitations/:invId`, () => HttpResponse.json({ success: true })),
  http.post(`${API_BASE}/invitations/:invId/resend`, () => HttpResponse.json({ success: true })),
  http.get(`${SUPABASE_BASE}/org_invitations`, () => HttpResponse.json([])),
  http.get(
    `${API_BASE}/user`,
    () => HttpResponse.json({
      id: "test-user",
      email: "test@example.com",
      first_name: "Test",
      last_name: "User",
      is_platform_admin: false
    })
  )
];
var server = setupServer(...handlers);

export { handlers, server };
