using Microsoft.EntityFrameworkCore;
using Monitoring.Core.Domain;
using Monitoring.Core.Domain.AssetGroupManagement;
using Monitoring.Core.Domain.AssetManagement;
using Monitoring.Core.Domain.AssetStatus;
using Monitoring.Core.Domain.CallManagement;
using Monitoring.Core.Domain.CameraManagement;
using Monitoring.Core.Domain.CheckListManagement;
using Monitoring.Core.Domain.EventManagement;
using Monitoring.Core.Domain.FireDepartmentManagement;
using Monitoring.Core.Domain.OrganizationManagement;
using Monitoring.Core.Domain.ReportManagement;
using Monitoring.Core.Domain.ServiceOrganizationManagement;
using Monitoring.Core.Domain.TokenManagement;
using Monitoring.Core.Domain.UserLogManagement;
using Monitoring.Core.Domain.UserSettingsManagement;
using Monitoring.Infrastructure.Abstractions;
using Monitoring.Infrastructure.Data.Configurations;

namespace Monitoring.Infrastructure.Data;

public class DataContext(DbContextOptions<DataContext> options, IPasswordService passwordService)
	: DbContext(options),
		IDataContext
{
	public DbSet<Role> Roles => Set<Role>();
	public DbSet<User> Users => Set<User>();
	public DbSet<Organization> Organizations => Set<Organization>();
	public DbSet<ServiceOrganization> ServiceOrganizations => Set<ServiceOrganization>();
	public DbSet<Token> Tokens => Set<Token>();
	public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
	public DbSet<Member> Members => Set<Member>();
	public DbSet<Access> Accesses => Set<Access>();

	public DbSet<Asset> Assets => Set<Asset>();
	public DbSet<Event> Events => Set<Event>();
	public DbSet<EventCode> EventCodes => Set<EventCode>();
	public DbSet<AssetGroup> AssetGroups => Set<AssetGroup>();
	public DbSet<AssetStatus> AssetStatuses => Set<AssetStatus>();
	public DbSet<ResponsiblePerson> ResponsiblePersons => Set<ResponsiblePerson>();
	public DbSet<Photo> Photos => Set<Photo>();
	public DbSet<Area> Areas => Set<Area>();
	public DbSet<Zone> Zones => Set<Zone>();
	public DbSet<LockedEventCode> LockedEventCodes => Set<LockedEventCode>();
	public DbSet<Fault> Faults => Set<Fault>();
	public DbSet<Alarm> Alarms => Set<Alarm>();
	public DbSet<AlarmScope> AlarmScopes => Set<AlarmScope>();
	public DbSet<AlarmScopeStatusChanging> AlarmScopeStatusHistory =>
		Set<AlarmScopeStatusChanging>();
	public DbSet<AlarmReset> AlarmResets => Set<AlarmReset>();
	public DbSet<Call> Calls => Set<Call>();
	public DbSet<AlarmFireDepartmentDispatch> AlarmFireDepartmentDispatches =>
		Set<AlarmFireDepartmentDispatch>();
	public DbSet<Camera> Cameras => Set<Camera>();
	public DbSet<CameraView> CameraViews => Set<CameraView>();
	public DbSet<FireDepartment> FireDepartments => Set<FireDepartment>();
	public DbSet<FireDepartmentAccess> FireDepartmentAccesses => Set<FireDepartmentAccess>();
	public DbSet<AlarmResetComment> AlarmResetComments => Set<AlarmResetComment>();
	public DbSet<AlarmResetCommentTranslate> AlarmResetCommentTranslates =>
		Set<AlarmResetCommentTranslate>();

	public DbSet<UserLog> UserLogs => Set<UserLog>();
	public DbSet<UserSettings> UserSettings => Set<UserSettings>();

	public DbSet<Report> Reports => Set<Report>();

	public DbSet<CheckListTemplate> CheckListTemplates => Set<CheckListTemplate>();
	public DbSet<CheckListTemplateItem> CheckListTemplateItems => Set<CheckListTemplateItem>();
	public DbSet<CheckListTemplateItemTranslation> CheckListTemplateItemTranslations =>
		Set<CheckListTemplateItemTranslation>();
	public DbSet<CheckList> CheckLists => Set<CheckList>();
	public DbSet<CheckListItem> CheckListItems => Set<CheckListItem>();

	protected override void OnModelCreating(ModelBuilder builder)
	{
		base.OnModelCreating(builder);

		// TODO: move superadmin user creation to seed data
		_ = builder.ApplyConfiguration(new UserConfiguration(passwordService));

		builder.ApplyConfigurationsFromAssembly(typeof(DataContext).Assembly);
	}
}
