//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Ajuna.NetApi.Model.Types.Base;
using Ajuna.ServiceLayer.Attributes;
using Ajuna.ServiceLayer.Storage;
using System.Collections.Generic;
using System.Threading.Tasks;


namespace Bajun.Network.NET.RestService.Generated.Storage
{
    
    
    /// <summary>
    /// IRandomnessStorage interface definition.
    /// </summary>
    public interface IRandomnessStorage : IStorage
    {
        
        /// <summary>
        /// >> RandomMaterial
        ///  Series of block headers from the last 81 blocks that acts as random seed material. This
        ///  is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
        ///  the oldest hash.
        /// </summary>
        Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT30 GetRandomMaterial();
    }
    
    /// <summary>
    /// RandomnessStorage class definition.
    /// </summary>
    public sealed class RandomnessStorage : IRandomnessStorage
    {
        
        /// <summary>
        /// _randomMaterialTypedStorage typed storage field
        /// </summary>
        private TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT30> _randomMaterialTypedStorage;
        
        /// <summary>
        /// RandomnessStorage constructor.
        /// </summary>
        public RandomnessStorage(IStorageDataProvider storageDataProvider, List<IStorageChangeDelegate> storageChangeDelegates)
        {
            this.RandomMaterialTypedStorage = new TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT30>("Randomness.RandomMaterial", storageDataProvider, storageChangeDelegates);
        }
        
        /// <summary>
        /// _randomMaterialTypedStorage property
        /// </summary>
        public TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT30> RandomMaterialTypedStorage
        {
            get
            {
                return _randomMaterialTypedStorage;
            }
            set
            {
                _randomMaterialTypedStorage = value;
            }
        }
        
        /// <summary>
        /// Connects to all storages and initializes the change subscription handling.
        /// </summary>
        public async Task InitializeAsync(Ajuna.ServiceLayer.Storage.IStorageDataProvider dataProvider)
        {
            await RandomMaterialTypedStorage.InitializeAsync("Randomness", "RandomMaterial");
        }
        
        /// <summary>
        /// Implements any storage change for Randomness.RandomMaterial
        /// </summary>
        [StorageChange("Randomness", "RandomMaterial")]
        public void OnUpdateRandomMaterial(string data)
        {
            RandomMaterialTypedStorage.Update(data);
        }
        
        /// <summary>
        /// >> RandomMaterial
        ///  Series of block headers from the last 81 blocks that acts as random seed material. This
        ///  is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
        ///  the oldest hash.
        /// </summary>
        public Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT30 GetRandomMaterial()
        {
            return RandomMaterialTypedStorage.Get();
        }
    }
}
