using System;
using AIRuntime.Runtime.Filesystem;
using System.Threading;

namespace AIRuntime.Runtime.Capabilities
{
    /// <summary>
    /// Shared execution context passed through the capability pipeline.
    /// </summary>
    public sealed class CapabilityContext
    {
        public CancellationToken CancellationToken { get; set; }
        /// <summary>
        /// Capability being executed.
        /// </summary>
        public ICapability Capability { get; set; }

        /// <summary>
        /// Raw JSON received from the AI.
        /// </summary>
        public string RawArguments { get; set; }

        /// <summary>
        /// Strongly typed arguments after deserialization.
        /// </summary>
        public object Arguments { get; set; }

        /// <summary>
        /// Serialized result returned to the AI.
        /// </summary>
        public string Result { get; set; }

        /// <summary>
        /// Filesystem used during execution.
        /// </summary>
        public IFileSystem FileSystem { get; set; }

        /// <summary>
        /// Exception captured during execution.
        /// </summary>
        public Exception Exception { get; set; }

        /// <summary>
        /// Start time of execution.
        /// </summary>
        public DateTime StartedUtc { get; } = DateTime.UtcNow;

        /// <summary>
        /// End time of execution.
        /// </summary>
        public DateTime FinishedUtc { get; set; }

        /// <summary>
        /// Total execution duration.
        /// </summary>
        public TimeSpan Duration =>
            FinishedUtc - StartedUtc;
    }
}