//------------------------------------------------------------------------------
// <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>
    /// IAuraExtStorage interface definition.
    /// </summary>
    public interface IAuraExtStorage : IStorage
    {
        
        /// <summary>
        /// >> Authorities
        ///  Serves as cache for the authorities.
        /// 
        ///  The authorities in AuRa are overwritten in `on_initialize` when we switch to a new session,
        ///  but we require the old authorities to verify the seal when validating a PoV. This will always
        ///  be updated to the latest AuRa authorities in `on_finalize`.
        /// </summary>
        Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT26 GetAuthorities();
    }
    
    /// <summary>
    /// AuraExtStorage class definition.
    /// </summary>
    public sealed class AuraExtStorage : IAuraExtStorage
    {
        
        /// <summary>
        /// _authoritiesTypedStorage typed storage field
        /// </summary>
        private TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT26> _authoritiesTypedStorage;
        
        /// <summary>
        /// AuraExtStorage constructor.
        /// </summary>
        public AuraExtStorage(IStorageDataProvider storageDataProvider, List<IStorageChangeDelegate> storageChangeDelegates)
        {
            this.AuthoritiesTypedStorage = new TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT26>("AuraExt.Authorities", storageDataProvider, storageChangeDelegates);
        }
        
        /// <summary>
        /// _authoritiesTypedStorage property
        /// </summary>
        public TypedStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT26> AuthoritiesTypedStorage
        {
            get
            {
                return _authoritiesTypedStorage;
            }
            set
            {
                _authoritiesTypedStorage = value;
            }
        }
        
        /// <summary>
        /// Connects to all storages and initializes the change subscription handling.
        /// </summary>
        public async Task InitializeAsync(Ajuna.ServiceLayer.Storage.IStorageDataProvider dataProvider)
        {
            await AuthoritiesTypedStorage.InitializeAsync("AuraExt", "Authorities");
        }
        
        /// <summary>
        /// Implements any storage change for AuraExt.Authorities
        /// </summary>
        [StorageChange("AuraExt", "Authorities")]
        public void OnUpdateAuthorities(string data)
        {
            AuthoritiesTypedStorage.Update(data);
        }
        
        /// <summary>
        /// >> Authorities
        ///  Serves as cache for the authorities.
        /// 
        ///  The authorities in AuRa are overwritten in `on_initialize` when we switch to a new session,
        ///  but we require the old authorities to verify the seal when validating a PoV. This will always
        ///  be updated to the latest AuRa authorities in `on_finalize`.
        /// </summary>
        public Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT26 GetAuthorities()
        {
            return AuthoritiesTypedStorage.Get();
        }
    }
}
