import type { Migration } from '@/shared/db';

export const callMigrations: readonly Migration[] = [
  {
    id: '2026-06-27_call_initial',
    sql: `
      CREATE TABLE IF NOT EXISTS macsync.calls (
        id               UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        device_id        UUID NOT NULL REFERENCES macsync.devices(id) ON DELETE CASCADE,
        external_id      TEXT NOT NULL,
        address          TEXT,
        normalized_address TEXT,
        contact_name     TEXT,
        direction        TEXT,
        call_type        TEXT,
        answered         BOOLEAN,
        duration_seconds REAL,
        started_at       TIMESTAMPTZ,
        service_provider TEXT,
        synced_at        TIMESTAMPTZ NOT NULL DEFAULT now(),
        UNIQUE(device_id, external_id)
      );
      CREATE INDEX IF NOT EXISTS idx_calls_device ON macsync.calls(device_id);
      CREATE INDEX IF NOT EXISTS idx_calls_started ON macsync.calls(started_at DESC);
      CREATE INDEX IF NOT EXISTS idx_calls_address ON macsync.calls(normalized_address);
    `,
  },
];
