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

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

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

        #endregion

        #region Dependencies (Injected)

        /// <summary>
        /// Gets or sets the value of the auth service (ab)
        /// </summary>
        [Inject] protected AuthService AuthService { 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 notification (ab)
        /// </summary>
        [Inject] protected INotificationService Notification { get; set; } = null!;

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

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

        #endregion

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

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