-- Create form_buttons table
CREATE TABLE form_buttons (
    id SERIAL PRIMARY KEY,
    form_id INTEGER NOT NULL,
    label VARCHAR(100) NOT NULL,
    action_type VARCHAR(50) NOT NULL,
    action_payload TEXT DEFAULT NULL,
    order_index INTEGER DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX form_buttons_form_idx ON form_buttons(form_id);

-- Insert button element type if missing
INSERT INTO element_types (tenant_id, branch_id, name, html_type, sql_type)
SELECT NULL, NULL, 'button', 'button', NULL
WHERE NOT EXISTS (SELECT 1 FROM element_types WHERE name = 'button');
