/**
 * Test data fixtures for database setup
 * All string IDs are prefixed with "test_" for easy cleanup
 */

import type { Exception, WeeklyAvailability } from "../../helpers/slots.js";

export interface TestUser {
  email: string;
  password: string;
  first_name: string;
  last_name: string;
  name: string;
  is_temporary: boolean;
}

export const TEST_USERS: Record<string, TestUser> = {
  owner: {
    email: "test_owner@example.com",
    password: "test_password_123",
    first_name: "Test",
    last_name: "Owner",
    name: "Test Owner",
    is_temporary: false,
  },
  temp: {
    email: "test_temp@example.com",
    password: "test_password_789",
    first_name: "Test",
    last_name: "Temporary",
    name: "Test Temporary",
    is_temporary: true,
  },
};

export interface TestTablo {
  id: string;
  name: string;
  color: string;
  status: "todo" | "in_progress" | "done";
  position: number;
  owner_key: string; // references TEST_USERS keys
}

export const TEST_TABLOS: TestTablo[] = [
  {
    id: "test_tablo_owner_private",
    name: "Test Private Tablo",
    color: "#3B82F6",
    status: "todo",
    position: 0,
    owner_key: "owner",
  },
  {
    id: "test_tablo_owner_shared",
    name: "Test Shared Tablo",
    color: "#10B981",
    status: "in_progress",
    position: 1,
    owner_key: "owner",
  },
  {
    id: "test_tablo_owner_private_2",
    name: "Test Private Tablo 2",
    color: "#8B5CF6",
    status: "in_progress",
    position: 2,
    owner_key: "owner",
  },
  {
    id: "test_tablo_owner_team",
    name: "Test Team Tablo",
    color: "#F59E0B",
    status: "todo",
    position: 3,
    owner_key: "owner",
  },
  {
    id: "test_tablo_owner_done",
    name: "Test Completed Tablo",
    color: "#14B8A6",
    status: "done",
    position: 4,
    owner_key: "owner",
  },
  {
    id: "test_tablo_temp_private",
    name: "Test Temp Tablo",
    color: "#EF4444",
    status: "done",
    position: 0,
    owner_key: "temp",
  },
  {
    id: "test_tablo_temp_private_2",
    name: "Test Temp Private 2",
    color: "#EC4899",
    status: "todo",
    position: 1,
    owner_key: "temp",
  },
  {
    id: "test_tablo_temp_shared_admin",
    name: "Test Temp Admin Tablo",
    color: "#6366F1",
    status: "in_progress",
    position: 2,
    owner_key: "temp",
  },
];

export interface TestTabloAccess {
  tablo_id: string;
  user_key: string; // references TEST_USERS keys
  granted_by_key: string;
  is_active: boolean;
  is_admin: boolean;
}

export const TEST_TABLO_ACCESS: TestTabloAccess[] = [
  // Temp has access to owner's shared tablo
  {
    tablo_id: "test_tablo_owner_shared",
    user_key: "temp",
    granted_by_key: "owner",
    is_active: true,
    is_admin: false,
  },
  // Temp has access to owner's team tablo
  {
    tablo_id: "test_tablo_owner_team",
    user_key: "temp",
    granted_by_key: "owner",
    is_active: true,
    is_admin: false,
  },
  // Owner has admin access to temp's shared tablo
  {
    tablo_id: "test_tablo_temp_shared_admin",
    user_key: "owner",
    granted_by_key: "temp",
    is_active: true,
    is_admin: true,
  },
];

export interface TestEvent {
  id: string;
  tablo_id: string;
  title: string;
  description: string;
  start_date: string; // YYYY-MM-DD
  start_time: string; // HH:MM
  end_time: string | null;
  created_by_key: string;
}

export const TEST_EVENTS: TestEvent[] = [
  {
    id: "test_event_1",
    tablo_id: "test_tablo_owner_private",
    title: "Test Meeting",
    description: "A test meeting event",
    start_date: "2025-11-15",
    start_time: "10:00",
    end_time: "11:00",
    created_by_key: "owner",
  },
  {
    id: "test_event_2",
    tablo_id: "test_tablo_owner_shared",
    title: "Test Workshop",
    description: "A test workshop event",
    start_date: "2025-11-16",
    start_time: "14:00",
    end_time: "16:00",
    created_by_key: "owner",
  },
];

export interface TestEventType {
  id: string;
  user_key: string;
  config: {
    name: string;
    description: string;
    duration: number;
    bufferTime?: number;
    maxBookingsPerDay?: number;
  };
  is_active: boolean;
}

export const TEST_EVENT_TYPES: TestEventType[] = [
  {
    id: "test_event_type_1",
    user_key: "owner",
    config: {
      name: "Test Consultation",
      description: "30-minute consultation",
      duration: 30,
      bufferTime: 15,
      maxBookingsPerDay: 5,
    },
    is_active: true,
  },
  {
    id: "test_event_type_2",
    user_key: "owner",
    config: {
      name: "Test Workshop",
      description: "1-hour workshop session",
      duration: 60,
      bufferTime: 0,
      maxBookingsPerDay: 3,
    },
    is_active: true,
  },
];

export interface TestNote {
  id: string;
  user_key: string;
  title: string;
  content: string;
}

export const TEST_NOTES: TestNote[] = [
  {
    id: "test_note_1",
    user_key: "owner",
    title: "Test Private Note",
    content: "This is a private test note for owner only",
  },
  {
    id: "test_note_2",
    user_key: "owner",
    title: "Test Shared Note",
    content: "This is a shared test note accessible in shared tablo",
  },
  {
    id: "test_note_3",
    user_key: "owner",
    title: "Test Global Note",
    content: "This note is shared across all tablos",
  },
  {
    id: "test_note_4",
    user_key: "owner",
    title: "Test Public Note",
    content: "This is a public note visible to everyone with access",
  },
  {
    id: "test_note_5",
    user_key: "owner",
    title: "Test Owner Private 2",
    content: "Another private note for owner",
  },
  {
    id: "test_note_6",
    user_key: "owner",
    title: "Test Team Note",
    content: "A note for the team tablo",
  },
  {
    id: "test_note_7",
    user_key: "temp",
    title: "Test Temp Private Note",
    content: "This is a private note for temp user",
  },
  {
    id: "test_note_8",
    user_key: "temp",
    title: "Test Temp Shared Note",
    content: "This note is shared with owner",
  },
  {
    id: "test_note_9",
    user_key: "temp",
    title: "Test Temp Public Note",
    content: "This is a public note from temp user",
  },
  {
    id: "test_note_10",
    user_key: "owner",
    title: "Test Meeting Notes",
    content: "Notes from the team meeting discussing project progress",
  },
];

export interface TestNoteAccess {
  note_id: string;
  user_key: string;
  tablo_id: string | null; // null means shared with all tablos
  is_active: boolean;
}

export const TEST_NOTE_ACCESS: TestNoteAccess[] = [
  // test_note_2: shared in owner's shared tablo
  {
    note_id: "test_note_2",
    user_key: "owner",
    tablo_id: "test_tablo_owner_shared",
    is_active: true,
  },
  // test_note_3: owner's global note (all tablos)
  {
    note_id: "test_note_3",
    user_key: "owner",
    tablo_id: null,
    is_active: true,
  },
  // test_note_4: public note in shared tablo
  {
    note_id: "test_note_4",
    user_key: "owner",
    tablo_id: "test_tablo_owner_shared",
    is_active: true,
  },
  // test_note_4: also in team tablo
  {
    note_id: "test_note_4",
    user_key: "owner",
    tablo_id: "test_tablo_owner_team",
    is_active: true,
  },
  // test_note_6: team note for team tablo
  {
    note_id: "test_note_6",
    user_key: "owner",
    tablo_id: "test_tablo_owner_team",
    is_active: true,
  },
  // test_note_8: temp's note shared in temp's shared tablo
  {
    note_id: "test_note_8",
    user_key: "temp",
    tablo_id: "test_tablo_temp_shared_admin",
    is_active: true,
  },
  // test_note_9: temp's public note shared globally
  {
    note_id: "test_note_9",
    user_key: "temp",
    tablo_id: null,
    is_active: true,
  },
  // test_note_10: meeting notes for team tablo
  {
    note_id: "test_note_10",
    user_key: "owner",
    tablo_id: "test_tablo_owner_team",
    is_active: true,
  },
];

export interface TestSharedNote {
  note_id: string;
  user_key: string;
  is_public: boolean;
}

export const TEST_SHARED_NOTES: TestSharedNote[] = [
  // test_note_2: owner's public shared note
  {
    note_id: "test_note_2",
    user_key: "owner",
    is_public: true,
  },
  // test_note_4: owner's public note in multiple tablos
  {
    note_id: "test_note_4",
    user_key: "owner",
    is_public: true,
  },
  // test_note_8: temp's public shared note
  {
    note_id: "test_note_8",
    user_key: "temp",
    is_public: true,
  },
  // test_note_9: temp's global public note
  {
    note_id: "test_note_9",
    user_key: "temp",
    is_public: true,
  },
];

export interface TestAvailability {
  user_key: string;
  availability_data: WeeklyAvailability;
  exceptions: Exception[];
}

export const TEST_AVAILABILITIES: TestAvailability[] = [
  {
    user_key: "owner",
    availability_data: {
      0: { enabled: true, timeRanges: [{ start: "09:00", end: "17:00" }] }, // Monday
      1: { enabled: true, timeRanges: [{ start: "09:00", end: "17:00" }] }, // Tuesday
      2: { enabled: true, timeRanges: [{ start: "09:00", end: "17:00" }] }, // Wednesday
      3: { enabled: true, timeRanges: [{ start: "09:00", end: "17:00" }] }, // Thursday
      4: { enabled: true, timeRanges: [{ start: "09:00", end: "17:00" }] }, // Friday
      5: { enabled: false, timeRanges: [] }, // Saturday
      6: { enabled: false, timeRanges: [] }, // Sunday
    },
    exceptions: [],
  },
];

export interface TestUserIntroduction {
  user_key: string;
  config: Record<string, unknown>;
}

export const TEST_USER_INTRODUCTIONS: TestUserIntroduction[] = [
  {
    user_key: "owner",
    config: {
      greeting: "Hello! Welcome to my calendar.",
      signature: "Best regards,\nTest Owner",
    },
  },
];

export interface TestFeedback {
  user_key: string;
  fd_type: "bug" | "feature" | "improvement" | "other";
  message: string;
}

export const TEST_FEEDBACKS: TestFeedback[] = [
  {
    user_key: "owner",
    fd_type: "feature",
    message: "This is a test feature request",
  },
];

export interface TestTabloInvite {
  invited_email: string;
  invited_by_key: string;
  tablo_id: string;
  is_pending: boolean;
}

export const TEST_TABLO_INVITES: TestTabloInvite[] = [
  {
    invited_email: "test_invited@example.com",
    invited_by_key: "owner",
    tablo_id: "test_tablo_owner_shared",
    is_pending: true,
  },
];
