CREATE TABLE IF NOT EXISTS call_recordings (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  recording_id TEXT NOT NULL UNIQUE,
  channel TEXT NOT NULL,
  call_id TEXT NOT NULL,
  interaction_id TEXT NULL,
  source_event_id TEXT NULL,
  file_name TEXT NOT NULL,
  storage_backend TEXT NOT NULL,
  storage_path TEXT NOT NULL,
  mime_type TEXT NOT NULL,
  size_bytes INTEGER NOT NULL,
  duration_seconds INTEGER NULL,
  checksum_sha256 TEXT NOT NULL,
  status TEXT NOT NULL,
  recorded_at TEXT NOT NULL,
  created_at TEXT NOT NULL,
  updated_at TEXT NOT NULL,
  archived_at TEXT NULL
);

CREATE INDEX IF NOT EXISTS ix_call_recordings_recording_id ON call_recordings (recording_id);
CREATE INDEX IF NOT EXISTS ix_call_recordings_channel ON call_recordings (channel);
CREATE INDEX IF NOT EXISTS ix_call_recordings_call_id ON call_recordings (call_id);
CREATE INDEX IF NOT EXISTS ix_call_recordings_interaction_id ON call_recordings (interaction_id);
CREATE INDEX IF NOT EXISTS ix_call_recordings_source_event_id ON call_recordings (source_event_id);
CREATE INDEX IF NOT EXISTS ix_call_recordings_storage_backend ON call_recordings (storage_backend);
CREATE INDEX IF NOT EXISTS ix_call_recordings_checksum_sha256 ON call_recordings (checksum_sha256);
CREATE INDEX IF NOT EXISTS ix_call_recordings_status ON call_recordings (status);
CREATE INDEX IF NOT EXISTS ix_call_recordings_recorded_at ON call_recordings (recorded_at);
CREATE INDEX IF NOT EXISTS ix_call_recordings_created_at ON call_recordings (created_at);
CREATE INDEX IF NOT EXISTS ix_call_recordings_updated_at ON call_recordings (updated_at);
CREATE INDEX IF NOT EXISTS ix_call_recordings_archived_at ON call_recordings (archived_at);
