CREATE TABLE IF NOT EXISTS call_logs (
    id         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    uuid       CHAR(36)        NOT NULL,
    caller_id  BIGINT UNSIGNED NOT NULL,
    callee_id  BIGINT UNSIGNED NOT NULL,
    type       ENUM('audio','video') NOT NULL,
    status     ENUM('missed','declined','answered','failed') NOT NULL,
    started_at DATETIME        DEFAULT NULL,
    ended_at   DATETIME        DEFAULT NULL,
    duration_s INT UNSIGNED    DEFAULT NULL,
    signal_data JSON           DEFAULT NULL,
    created_at DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uq_uuid (uuid),
    FOREIGN KEY (caller_id) REFERENCES users(id) ON DELETE RESTRICT,
    FOREIGN KEY (callee_id) REFERENCES users(id) ON DELETE RESTRICT,
    INDEX idx_caller (caller_id),
    INDEX idx_callee (callee_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
