// Copyright (c) Microsoft. All rights reserved. using System; using System.Text.Json.Serialization; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI.Workflows; /// /// Represents a unique key within a specific scope, combining a scope identifier and a key string. /// public sealed class ScopeKey { /// /// The identifier for the scope associated with this key. /// public ScopeId ScopeId { get; } /// /// The unique key within the specified scope. /// public string Key { get; } /// /// Initializes a new instance of the class. /// /// The unique identifier for the executor. /// The name of the scope, if any. /// The unique key within the specified scope. public ScopeKey(string executorId, string? scopeName, string key) : this(new ScopeId(Throw.IfNullOrEmpty(executorId), scopeName), key) { } /// /// Iniitalizes a new instance of the class. /// /// The associated with this key. /// The unique key within the specified scope. [JsonConstructor] public ScopeKey(ScopeId scopeId, string key) { this.ScopeId = Throw.IfNull(scopeId); this.Key = Throw.IfNullOrEmpty(key); } /// public override string ToString() { return $"{this.ScopeId}/{this.Key}"; } /// public override bool Equals(object? obj) { if (obj is ScopeKey other) { // Unlike ScopeId, ScopeKey is equal only if both the Executor and ScopeName are the same return this.ScopeId.Equals(other.ScopeId) && this.Key == other.Key; } return false; } /// public override int GetHashCode() { return HashCode.Combine(this.ScopeId, this.Key); } }