//------------------------------------------------------------------------------
// <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>
    /// IPreimageStorage interface definition.
    /// </summary>
    public interface IPreimageStorage : IStorage
    {
        
        /// <summary>
        /// >> StatusFor
        ///  The request status of a given hash.
        /// </summary>
        Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus GetStatusFor(string key);
        
        /// <summary>
        /// >> PreimageFor
        /// </summary>
        Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20 GetPreimageFor(string key);
    }
    
    /// <summary>
    /// PreimageStorage class definition.
    /// </summary>
    public sealed class PreimageStorage : IPreimageStorage
    {
        
        /// <summary>
        /// _statusForTypedStorage typed storage field
        /// </summary>
        private TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus> _statusForTypedStorage;
        
        /// <summary>
        /// _preimageForTypedStorage typed storage field
        /// </summary>
        private TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20> _preimageForTypedStorage;
        
        /// <summary>
        /// PreimageStorage constructor.
        /// </summary>
        public PreimageStorage(IStorageDataProvider storageDataProvider, List<IStorageChangeDelegate> storageChangeDelegates)
        {
            this.StatusForTypedStorage = new TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus>("Preimage.StatusFor", storageDataProvider, storageChangeDelegates);
            this.PreimageForTypedStorage = new TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20>("Preimage.PreimageFor", storageDataProvider, storageChangeDelegates);
        }
        
        /// <summary>
        /// _statusForTypedStorage property
        /// </summary>
        public TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus> StatusForTypedStorage
        {
            get
            {
                return _statusForTypedStorage;
            }
            set
            {
                _statusForTypedStorage = value;
            }
        }
        
        /// <summary>
        /// _preimageForTypedStorage property
        /// </summary>
        public TypedMapStorage<Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20> PreimageForTypedStorage
        {
            get
            {
                return _preimageForTypedStorage;
            }
            set
            {
                _preimageForTypedStorage = value;
            }
        }
        
        /// <summary>
        /// Connects to all storages and initializes the change subscription handling.
        /// </summary>
        public async Task InitializeAsync(Ajuna.ServiceLayer.Storage.IStorageDataProvider dataProvider)
        {
            await StatusForTypedStorage.InitializeAsync("Preimage", "StatusFor");
            await PreimageForTypedStorage.InitializeAsync("Preimage", "PreimageFor");
        }
        
        /// <summary>
        /// Implements any storage change for Preimage.StatusFor
        /// </summary>
        [StorageChange("Preimage", "StatusFor")]
        public void OnUpdateStatusFor(string key, string data)
        {
            StatusForTypedStorage.Update(key, data);
        }
        
        /// <summary>
        /// >> StatusFor
        ///  The request status of a given hash.
        /// </summary>
        public Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus GetStatusFor(string key)
        {
            if ((key == null))
            {
                return null;
            }
            if (StatusForTypedStorage.Dictionary.TryGetValue(key, out Bajun.Network.NET.NetApiExt.Generated.Model.pallet_preimage.EnumRequestStatus result))
            {
                return result;
            }
            else
            {
                return null;
            }
        }
        
        /// <summary>
        /// Implements any storage change for Preimage.PreimageFor
        /// </summary>
        [StorageChange("Preimage", "PreimageFor")]
        public void OnUpdatePreimageFor(string key, string data)
        {
            PreimageForTypedStorage.Update(key, data);
        }
        
        /// <summary>
        /// >> PreimageFor
        /// </summary>
        public Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20 GetPreimageFor(string key)
        {
            if ((key == null))
            {
                return null;
            }
            if (PreimageForTypedStorage.Dictionary.TryGetValue(key, out Bajun.Network.NET.NetApiExt.Generated.Model.sp_core.bounded.bounded_vec.BoundedVecT20 result))
            {
                return result;
            }
            else
            {
                return null;
            }
        }
    }
}
