ALTER TABLE bookings ADD COLUMN cancelled_at TEXT;
ALTER TABLE bookings ADD COLUMN updated_at TEXT;
ALTER TABLE bookings ADD COLUMN calendar_provider TEXT NOT NULL DEFAULT 'google';
ALTER TABLE bookings ADD COLUMN calendar_sync_status TEXT NOT NULL DEFAULT 'synced';
ALTER TABLE bookings ADD COLUMN calendar_sync_error TEXT;
ALTER TABLE bookings ADD COLUMN calendar_sync_updated_at TEXT;

CREATE TABLE IF NOT EXISTS recurring_unavailable_periods (
  id TEXT PRIMARY KEY,
  weekdays TEXT NOT NULL,
  start_time TEXT NOT NULL,
  end_time TEXT NOT NULL,
  label TEXT,
  created_at TEXT NOT NULL DEFAULT (datetime('now')),
  updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS availability_blocks (
  id TEXT PRIMARY KEY,
  date TEXT NOT NULL,
  start_time TEXT,
  end_time TEXT,
  all_day INTEGER NOT NULL DEFAULT 0,
  label TEXT,
  created_at TEXT NOT NULL DEFAULT (datetime('now')),
  updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE INDEX IF NOT EXISTS idx_recurring_unavailable_periods_weekdays ON recurring_unavailable_periods(weekdays);
CREATE INDEX IF NOT EXISTS idx_availability_blocks_date ON availability_blocks(date);
CREATE INDEX IF NOT EXISTS idx_bookings_sync_status ON bookings(calendar_sync_status);
