CREATE TABLE IF NOT EXISTS form_submissions (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    source_type VARCHAR(32) NOT NULL,
    source_id INT UNSIGNED NULL,
    source_label VARCHAR(255) NULL,
    source_url VARCHAR(255) NULL,
    form_key VARCHAR(64) NULL,
    request_type VARCHAR(32) NOT NULL DEFAULT 'contact',
    full_name VARCHAR(190) NOT NULL,
    email VARCHAR(190) NOT NULL,
    phone VARCHAR(64) NULL,
    company VARCHAR(190) NULL,
    message LONGTEXT NULL,
    metadata_json LONGTEXT NULL,
    status VARCHAR(32) NOT NULL DEFAULT 'new',
    processed_at DATETIME NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_form_submissions_source (source_type, source_id),
    KEY idx_form_submissions_request_type (request_type),
    KEY idx_form_submissions_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
