<?php
if (!defined('ABSPATH')) exit;

function asana_automator_clear_field_after_done($config, $token, $task) {
    $field_gid = trim($config['field_gid'] ?? '');
    if (!$field_gid || empty($task['completed']) || empty($task['gid'])) return;

    wp_remote_put("https://app.asana.com/api/1.0/tasks/{$task['gid']}", [
        'headers' => [
            'Authorization' => 'Bearer ' . $token,
            'Content-Type' => 'application/json'
        ],
        'body' => json_encode([
            'custom_fields' => [
                $field_gid => null
            ]
        ])
    ]);
}
