-- name: missioncontrol__insert_command :one
INSERT INTO mission_control_commands (
    project_id,
    command_kind,
    target_entity_id,
    actor_id,
    business_intent_key,
    correlation_id,
    status,
    failure_reason,
    approval_request_id,
    approval_state,
    approval_requested_at,
    approval_decided_at,
    payload,
    result_payload,
    provider_delivery_ids,
    requested_at,
    updated_at,
    reconciled_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, COALESCE($16, NOW()), COALESCE($17, NOW()), $18)
RETURNING
    id::text AS id,
    project_id::text AS project_id,
    command_kind,
    target_entity_id,
    actor_id,
    business_intent_key,
    correlation_id,
    status,
    failure_reason,
    approval_request_id::text AS approval_request_id,
    approval_state,
    approval_requested_at,
    approval_decided_at,
    payload AS payload_json,
    result_payload AS result_payload_json,
    provider_delivery_ids AS provider_deliveries_json,
    lease_owner,
    lease_until,
    requested_at,
    updated_at,
    reconciled_at;
