using System; using System.Collections.Generic; using System.Linq; using FrostFS.SDK.ClientV2; using FrostFS.SDK.Cryptography; using FrostFS.SDK.ClientV2.Mappers.GRPC; using Google.Protobuf; namespace FrostFS.SDK; public class FrostFsContainerInfo { private FrostFS.Container.Container.Types.Attribute[]? grpsAttributes; private List? attributes; private FrostFsPlacementPolicy? placementPolicy; private Guid? nonce; private Container.Container container; public FrostFsContainerInfo( BasicAcl basicAcl, FrostFsPlacementPolicy placementPolicy, List? attributes = null, FrostFsVersion? version = null, FrostFsOwner? owner = null, Guid? nonce = null) { BasicAcl = basicAcl; this.placementPolicy = placementPolicy; this.attributes = attributes; Version = version; Owner = owner; this.nonce = nonce; } internal FrostFsContainerInfo(Container.Container container) { this.container = container; } public Guid Nonce { get { nonce ??= container?.Nonce != null ? container.Nonce.ToUuid() : Guid.NewGuid(); return nonce.Value; } } public BasicAcl BasicAcl { get; private set; } public FrostFsPlacementPolicy? PlacementPolicy { get { placementPolicy ??= container.PlacementPolicy?.ToModel(); return placementPolicy; } } public List? Attributes { get { if (attributes == null && grpsAttributes != null) attributes = grpsAttributes.Select(a => new FrostFsAttribute(a.Key, a.Value)).ToList(); return attributes; } } public FrostFsVersion? Version { get; private set; } public FrostFsOwner? Owner { get; private set; } internal Container.Container.Types.Attribute[]? GetGrpsAttributes() { grpsAttributes ??= Attributes? .Select(a => new Container.Container.Types.Attribute { Key = a.Key, Value = a.Value }) .ToArray(); return grpsAttributes; } internal Container.Container GetContainer() { if (this.container == null) { this.container = new Container.Container() { BasicAcl = (uint)BasicAcl, PlacementPolicy = PlacementPolicy.ToMessage(), Nonce = ByteString.CopyFrom(Nonce.ToBytes()), OwnerId = Owner?.OwnerID, Version = Version?.Version }; var attribs = GetGrpsAttributes(); if (attribs != null) this.container.Attributes.AddRange(attribs); } return this.container; } }