using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Auth;
using FoodsharingSiegen.Server.Data.Service;
using FoodsharingSiegen.Server.Service;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;

namespace FoodsharingSiegen.Server.BaseClasses
{
    /// <summary>
    ///     The fs base class (a. beging, 08.04.2022)
    /// </summary>
    /// <seealso cref="ComponentBase" />
    public class FsBase : ComponentBase
    {
        #region Dependencies

        [Inject]
        private IOptions<AppSettings> AppSettingsContainer { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the value of the audit service (ab)
        /// </summary>
        [Inject]
        private AuditService AuditService { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the value of the auth service (ab)
        /// </summary>
        [Inject]
        protected AuthService AuthService { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the service that interacts with the browser's local storage.
        /// </summary>
        [Inject]
        protected LocalStorageService LocalStorageService { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the modal service for handling modals within the application
        /// </summary>
        [Inject]
        protected IModalService ModalService { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the value of the navigation manager (ab)
        /// </summary>
        [Inject]
        protected NavigationManager NavigationManager { get; set; } = null!;

        /// <summary>
        ///     Gets or sets the value of the notification (ab)
        /// </summary>
        [Inject]
        protected INotificationService Notification { get; set; } = null!;

        #endregion

        #region Protected Properties

        /// Provides application-specific settings used to configure the behavior and display of the application.
        /// The AppSettings class encapsulates information such as the application title and other configurable parameters.
        protected AppSettings AppSettings => AppSettingsContainer.Value;

        /// <summary>
        ///     Gets the value of the current user (ab)
        /// </summary>
        protected User CurrentUser => AuthService?.User ?? new User();

        #endregion

        #region Override OnInitializedAsync

        /// <summary>
        ///     Ons the initialized (a. beging, 11.04.2022)
        /// </summary>
        protected override async Task OnInitializedAsync()
        {
            await AuthService.Initialize();
            await InitializeDataAsync();
            await base.OnInitializedAsync();
        }

        #endregion

        #region Protected Method InitializeDataAsync

        /// <summary>
        ///     Initialize data here, Database Actions belong here
        /// </summary>
        protected virtual async Task InitializeDataAsync() => await Task.CompletedTask;

        #endregion

        #region Protected Method RefreshState

        /// <summary>
        ///     Refreshes the state (a. beging, 21.05.2022)
        /// </summary>
        protected async Task RefreshState()
        {
            await AuthService?.RefreshState()!;
        }

        #endregion
    }
}