using System; using Frostfs.V2.Ape; namespace FrostFS.SDK.ClientV2; public struct FrostFsChainTarget(FrostFsTargetType type, string name) : IEquatable { private ChainTarget? chainTarget; public FrostFsTargetType Type { get; } = type; public string Name { get; } = name; internal ChainTarget GetChainTarget() { return chainTarget ??= new ChainTarget { Type = GetTargetType(Type), Name = Name }; } private static TargetType GetTargetType(FrostFsTargetType type) { return type switch { FrostFsTargetType.Undefined => TargetType.Undefined, FrostFsTargetType.Namespace => TargetType.Namespace, FrostFsTargetType.Container => TargetType.Container, FrostFsTargetType.User => TargetType.User, FrostFsTargetType.Group => TargetType.Group, _ => throw new ArgumentException("Unexpected value for TargetType", nameof(type)), }; } public override readonly bool Equals(object obj) { var target = (FrostFsChainTarget)obj; return Equals(target); } public override readonly int GetHashCode() { return $"{Name}{Type}".GetHashCode(); } public static bool operator ==(FrostFsChainTarget left, FrostFsChainTarget right) { return left.Equals(right); } public static bool operator !=(FrostFsChainTarget left, FrostFsChainTarget right) { return !(left == right); } public readonly bool Equals(FrostFsChainTarget other) { return Type == other.Type && Name.Equals(other.Name, StringComparison.Ordinal); } }