using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Auth;
using FoodsharingSiegen.Server.Data.Service;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Options;
namespace FoodsharingSiegen.Server.BaseClasses
{
///
/// The fs base class (a. beging, 08.04.2022)
///
///
public class FsBase : ComponentBase
{
#region Dependencies
[Inject]
private IOptions AppSettingsContainer { get; set; } = null!;
///
/// Gets or sets the value of the audit service (ab)
///
[Inject]
private AuditService AuditService { get; set; } = null!;
///
/// Gets or sets the value of the auth service (ab)
///
[Inject]
protected AuthService AuthService { get; set; } = null!;
///
/// Gets or sets the modal service for handling modals within the application
///
[Inject]
protected IModalService ModalService { get; set; } = null!;
///
/// Gets or sets the value of the navigation manager (ab)
///
[Inject]
protected NavigationManager NavigationManager { get; set; } = null!;
///
/// Gets or sets the value of the notification (ab)
///
[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;
///
/// Gets the value of the current user (ab)
///
protected User CurrentUser => AuthService?.User ?? new User();
#endregion
#region Private Fields
private bool _dataInitialized;
#endregion
#region Override OnInitializedAsync
///
/// Ons the initialized (a. beging, 11.04.2022)
///
protected override async Task OnInitializedAsync()
{
await AuthService.Initialize();
await base.OnInitializedAsync();
}
#endregion
#region Override SetParametersAsync
///
public override async Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
if (!_dataInitialized)
{
_dataInitialized = true;
await InitializeDataAsync();
}
// Da die Parameter bereits gesetzt wurden, kann die Basisklasse am Ende aufgerufen werden.
await base.SetParametersAsync(ParameterView.Empty);
}
#endregion
#region Protected Method InitializeDataAsync
///
/// Initialize data here, Database Actions belong here
///
protected virtual async Task InitializeDataAsync() => await Task.CompletedTask;
#endregion
#region Protected Method RefreshState
///
/// Refreshes the state (a. beging, 21.05.2022)
///
protected async Task RefreshState()
{
await AuthService?.RefreshState()!;
}
#endregion
}
}