-- Workflow Engine v1.0 - reusable master definitions
-- Run after 01_workflow_schema.sql. The script is safe to re-run.


INSERT INTO workflow_component_type
    (code, name, renderer_file, description, properties_json, status, sort_order, created_at)
VALUES
    ('FORM', 'Form', 'form.php', 'Standard field container.', NULL, 1, 10, NOW()),
    ('MATRIX', 'Matrix', 'matrix.php', 'Tabular field matrix.', NULL, 1, 20, NOW()),
    ('REPEATER', 'Repeater', 'repeater.php', 'Repeatable field row container.', NULL, 1, 30, NOW()),
    ('CARD', 'Card', 'card.php', 'Information card.', NULL, 1, 40, NOW()),
    ('UPLOAD', 'Upload', 'upload.php', 'File upload container.', NULL, 1, 50, NOW()),
    ('SUMMARY', 'Summary', 'summary.php', 'Read-only value summary.', NULL, 1, 60, NOW()),
    ('TABLE', 'Table', 'table.php', 'Read-only dataset table.', NULL, 1, 70, NOW()),
    ('HTML', 'HTML', 'html.php', 'Sanitized static HTML content.', NULL, 1, 80, NOW()),
    ('DIVIDER', 'Divider', 'divider.php', 'Visual section divider.', NULL, 1, 90, NOW())
ON DUPLICATE KEY UPDATE
    name = VALUES(name), renderer_file = VALUES(renderer_file), description = VALUES(description),
    status = VALUES(status), sort_order = VALUES(sort_order), updated_at = NOW();

INSERT INTO workflow_lookup
    (lookup_group, code, name, value, status, sort_order, created_at)
VALUES
    ('workflow_status', 'DRAFT', 'Draft', 'DRAFT', 1, 10, NOW()),
    ('workflow_status', 'PUBLISHED', 'Published', 'PUBLISHED', 1, 20, NOW()),
    ('workflow_status', 'ACTIVE', 'Active', 'ACTIVE', 1, 30, NOW()),
    ('workflow_status', 'ARCHIVED', 'Archived', 'ARCHIVED', 1, 40, NOW()),
    ('instance_status', 'DRAFT', 'Draft', 'DRAFT', 1, 10, NOW()),
    ('instance_status', 'IN_PROGRESS', 'In Progress', 'IN_PROGRESS', 1, 20, NOW()),
    ('instance_status', 'SUBMITTED', 'Submitted', 'SUBMITTED', 1, 30, NOW()),
    ('instance_status', 'COMPLETED', 'Completed', 'COMPLETED', 1, 40, NOW()),
    ('instance_status', 'CANCELLED', 'Cancelled', 'CANCELLED', 1, 50, NOW()),
    ('field_type', 'TEXT', 'Text', 'TEXT', 1, 10, NOW()),
    ('field_type', 'NUMBER', 'Number', 'NUMBER', 1, 20, NOW()),
    ('field_type', 'EMAIL', 'Email', 'EMAIL', 1, 30, NOW()),
    ('field_type', 'PASSWORD', 'Password', 'PASSWORD', 1, 40, NOW()),
    ('field_type', 'DATE', 'Date', 'DATE', 1, 50, NOW()),
    ('field_type', 'TIME', 'Time', 'TIME', 1, 60, NOW()),
    ('field_type', 'DATETIME', 'Date and Time', 'DATETIME', 1, 70, NOW()),
    ('field_type', 'TEXTAREA', 'Text Area', 'TEXTAREA', 1, 80, NOW()),
    ('field_type', 'EDITOR', 'Rich Text Editor', 'EDITOR', 1, 90, NOW()),
    ('field_type', 'SELECT', 'Select', 'SELECT', 1, 100, NOW()),
    ('field_type', 'MULTISELECT', 'Multi Select', 'MULTISELECT', 1, 110, NOW()),
    ('field_type', 'RADIO', 'Radio', 'RADIO', 1, 120, NOW()),
    ('field_type', 'CHECKBOX', 'Checkbox', 'CHECKBOX', 1, 130, NOW()),
    ('field_type', 'SWITCH', 'Switch', 'SWITCH', 1, 140, NOW()),
    ('field_type', 'FILE', 'File', 'FILE', 1, 150, NOW()),
    ('field_type', 'IMAGE', 'Image', 'IMAGE', 1, 160, NOW()),
    ('field_type', 'LABEL', 'Label', 'LABEL', 1, 170, NOW()),
    ('field_type', 'HIDDEN', 'Hidden', 'HIDDEN', 1, 180, NOW()),
    ('field_type', 'BUTTON', 'Button', 'BUTTON', 1, 190, NOW()),
    ('datasource_type', 'STATIC', 'Static Options', 'STATIC', 1, 10, NOW()),
    ('datasource_type', 'TABLE', 'Database Table', 'TABLE', 1, 20, NOW()),
    ('datasource_type', 'SQL', 'SQL Query', 'SQL', 1, 30, NOW()),
    ('datasource_type', 'API', 'API', 'API', 1, 40, NOW()),
    ('datasource_type', 'CALLBACK', 'PHP Callback', 'CALLBACK', 1, 50, NOW()),
    ('datasource_type', 'JSON', 'JSON Data', 'JSON', 1, 60, NOW()),
    ('datasource_type', 'AJAX', 'AJAX Endpoint', 'AJAX', 1, 70, NOW()),
    ('validation_type', 'REQUIRED', 'Required', 'REQUIRED', 1, 10, NOW()),
    ('validation_type', 'REGEX', 'Regular Expression', 'REGEX', 1, 20, NOW()),
    ('validation_type', 'MIN', 'Minimum', 'MIN', 1, 30, NOW()),
    ('validation_type', 'MAX', 'Maximum', 'MAX', 1, 40, NOW()),
    ('validation_type', 'UNIQUE', 'Unique', 'UNIQUE', 1, 50, NOW()),
    ('validation_type', 'CALLBACK', 'PHP Callback', 'CALLBACK', 1, 60, NOW()),
    ('validation_type', 'API', 'API', 'API', 1, 70, NOW()),
    ('validation_type', 'CROSS_FIELD', 'Cross Field', 'CROSS_FIELD', 1, 80, NOW()),
    ('validation_type', 'DATE_COMPARE', 'Date Comparison', 'DATE_COMPARE', 1, 90, NOW()),
    ('condition_action', 'SHOW', 'Show', 'SHOW', 1, 10, NOW()),
    ('condition_action', 'HIDE', 'Hide', 'HIDE', 1, 20, NOW()),
    ('condition_action', 'ENABLE', 'Enable', 'ENABLE', 1, 30, NOW()),
    ('condition_action', 'DISABLE', 'Disable', 'DISABLE', 1, 40, NOW()),
    ('condition_action', 'READONLY', 'Readonly', 'READONLY', 1, 50, NOW()),
    ('condition_action', 'REQUIRED', 'Required', 'REQUIRED', 1, 60, NOW()),
    ('condition_action', 'CALCULATE', 'Calculate', 'CALCULATE', 1, 70, NOW()),
    ('condition_action', 'VALIDATE', 'Validate', 'VALIDATE', 1, 80, NOW()),
    ('condition_action', 'FILTER_DATASOURCE', 'Filter Datasource', 'FILTER_DATASOURCE', 1, 90, NOW()),
    ('calculation_type', 'FORMULA', 'Formula', 'FORMULA', 1, 10, NOW()),
    ('calculation_type', 'SQL', 'SQL', 'SQL', 1, 20, NOW()),
    ('calculation_type', 'CALLBACK', 'PHP Callback', 'CALLBACK', 1, 30, NOW()),
    ('calculation_type', 'API', 'API', 'API', 1, 40, NOW()),
    ('event_name', 'BEFORE_LOAD', 'Before Load', 'BEFORE_LOAD', 1, 10, NOW()),
    ('event_name', 'AFTER_LOAD', 'After Load', 'AFTER_LOAD', 1, 20, NOW()),
    ('event_name', 'BEFORE_SAVE', 'Before Save', 'BEFORE_SAVE', 1, 30, NOW()),
    ('event_name', 'AFTER_SAVE', 'After Save', 'AFTER_SAVE', 1, 40, NOW()),
    ('event_name', 'BEFORE_SUBMIT', 'Before Submit', 'BEFORE_SUBMIT', 1, 50, NOW()),
    ('event_name', 'AFTER_SUBMIT', 'After Submit', 'AFTER_SUBMIT', 1, 60, NOW()),
    ('event_name', 'BEFORE_DELETE', 'Before Delete', 'BEFORE_DELETE', 1, 70, NOW()),
    ('event_name', 'AFTER_DELETE', 'After Delete', 'AFTER_DELETE', 1, 80, NOW())
ON DUPLICATE KEY UPDATE
    name = VALUES(name), value = VALUES(value), status = VALUES(status), sort_order = VALUES(sort_order), updated_at = NOW();
