package com.tt.honeyDue.widget

import android.content.Context
import androidx.glance.GlanceId
import androidx.glance.action.ActionParameters
import androidx.glance.appwidget.action.ActionCallback

/**
 * Glance [ActionCallback] wired to the "complete task" button on
 * [HoneyDueLargeWidget] (and wherever else Stream K surfaces the control).
 *
 * The callback itself is deliberately thin — all policy lives in
 * [WidgetActionProcessor]. This keeps the Glance action registration simple
 * (required for Glance's reflective `actionRunCallback<CompleteTaskAction>`
 * pattern) and lets the processor be unit-tested without needing a Glance
 * runtime.
 *
 * iOS parity: mirrors `iosApp/HoneyDue/AppIntent.swift` `CompleteTaskIntent`.
 */
class CompleteTaskAction : ActionCallback {

    override suspend fun onAction(
        context: Context,
        glanceId: GlanceId,
        parameters: ActionParameters
    ) {
        val taskId = parameters[taskIdKey] ?: return
        WidgetActionProcessor.processComplete(context, taskId)
    }

    companion object {
        /**
         * Parameter key used by widget task rows to pass the clicked task's
         * id. Parameter name (`task_id`) matches the iOS `AppIntent`
         * parameter for discoverability.
         */
        val taskIdKey: ActionParameters.Key<Long> = ActionParameters.Key("task_id")
    }
}
