<?php

//includes/automation-registry.php

if (!defined('ABSPATH')) exit;

function asana_automator_get_registered_automations() {
    return [
        'delete_completed_tasks' => [
            'label'       => '🗑 Delete completed tasks',
            'description' => 'Deletes completed tasks from selected section(s).',
            'handler'     => 'asana_automator_delete_completed_tasks',
            'params'      => []
        ],
        'email_on_section_entry' => [
            'label'       => '📧 Email when task enters section',
            'description' => 'Sends an email when a task appears in the section.',
            'handler'     => 'asana_automator_email_on_section_entry',
            'params'      => [
                'email_field_gid',
                'first_name',
                'last_name',
                'marker_label',
                'email_subject_template',
                'email_body_template',
                'completion_state'  // ✅ added here!
            ]
        ],
        'email_client_on_new_team_comment' => [
            'label'       => '💬➡️📧 Email client on new team comment',
            'description' => 'Uses webhook comment events to email the client when an internal team comment is added.',
            'handler'     => 'asana_automator_email_client_on_new_team_comment',
            'params'      => [
                'email_field_gid',
                'first_name',
                'last_name',
                'marker_label',
                'email_subject_template',
                'email_body_template',
            ]
        ],
        'email_client_gateway_on_completion' => [
            'label'       => '✅➡️📧 Email client when task completed',
            'description' => 'Sends a gateway email to the client when the task is completed, using a magic link and optional auto-refresh.',
            'handler'     => 'asana_automator_email_client_gateway_on_completion',
            'params'      => [
                'email_field_gid',
                'first_name',
                'last_name',
                'marker_label',
                'email_subject_template',
                'email_body_template',
                'include_gateway_pin',
                'auto_refresh_gateway',
            ]
        ],
        'tag_on_section_entry' => [
            'label'       => '🏷 Add tag when task enters section',
            'description' => 'Adds a tag to any task that enters the section.',
            'handler'     => 'asana_automator_tag_on_section_entry',
            'params'      => ['tag_gid']
        ],
        'clear_field_after_done' => [
            'label'       => '🧹 Clear field when task completed',
            'description' => 'Removes the value from a custom field when a task is completed.',
            'handler'     => 'asana_automator_clear_field_after_done',
            'params'      => ['field_gid']
        ],
        'cleanup_on_completion' => [
            'label'       => '🧼 Cleanup on task completion',
            'description' => 'When a task is completed, optionally delete attachments, clear selected fields, and redact notes text.',
            'handler'     => 'asana_automator_cleanup_on_completion',
            'params'      => [
                'delete_attachments_on_complete',
                'delete_local_client_gateway_on_complete',
                'complete_private_companion_on_complete',
                'remove_private_companion_references_on_complete',
                'cleanup_field_gids',
                'clear_notes_on_complete',
                'notes_redact_phrases',
                'dry_run',
            ]
        ],
        'comment_on_section_move' => [
            'label'       => '💬 Comment when task enters section',
            'description' => 'Adds a comment to the task when it appears in the selected section.',
            'handler'     => 'asana_automator_comment_on_section_move',
            'params'      => ['comment_text']
        ],
        'map_fields_from_description' => [
            'label'       => '🧭 Map fields from description',
            'description' => 'Reads key/value lines from task description and maps values into Asana custom fields.',
            'handler'     => 'asana_automator_map_fields_from_description',
            'params'      => [
                'trigger_phrase',
                'marker_label',
                'overwrite_existing',
                'mapping_profile_key',
                'mapping_rules_json',
                'dry_run',
            ]
        ]
    ];
}
