using Khaemhat.Core.Instance;
using Khaemhat.Core.Security;
using Khaemhat.Data.Mapping;
namespace Khaemhat.Data.SystemDatabase;
/// The account columns shared by sys_users and users.
internal static class AccountColumns
{
public static void Configure(EntityMap map)
where T : class, IAccount, new()
{
map.Map(x => x.UserName).MaxLength(100);
map.Map(x => x.DisplayName).MaxLength(200);
map.Map(x => x.Email).MaxLength(254);
map.Map(x => x.PasswordHash).MaxLength(200);
map.Map(x => x.PasswordHistory).Json();
map.Map(x => x.TotpRecoveryCodes).Json();
map.Map(x => x.RecoveryTokenHash).MaxLength(64);
}
}
/// Map of to sys_users.
public sealed class SystemUserMap : EntityMap
{
/// Creates the map.
public SystemUserMap()
{
ToTable("sys_users");
AccountColumns.Configure(this);
Map(x => x.LinkedCompanyCode).MaxLength(20);
}
}
/// Map of to sys_sessions.
public sealed class SystemSessionMap : EntityMap
{
/// Creates the map.
public SystemSessionMap()
{
ToTable("sys_sessions");
SessionColumns.Configure(this);
}
}
/// The session columns shared by sys_sessions and user_sessions.
internal static class SessionColumns
{
public static void Configure(EntityMap map)
where T : SessionRecord, new()
{
map.Map(x => x.TokenHash).MaxLength(64);
map.Map(x => x.CompanyCode).MaxLength(20);
map.Map(x => x.IpAddress).MaxLength(64);
map.Map(x => x.UserAgent).MaxLength(400);
map.Map(x => x.RevokedReason).MaxLength(100);
}
}
/// Map of to sys_roles_templates.
public sealed class RoleTemplateMap : EntityMap
{
/// Creates the map.
public RoleTemplateMap()
{
ToTable("sys_roles_templates");
Map(x => x.Code).MaxLength(50);
Map(x => x.Name).MaxLength(100);
Map(x => x.Permissions).Json();
}
}
/// Map of to sys_licenses.
public sealed class LicenseRecordMap : EntityMap
{
/// Creates the map.
public LicenseRecordMap()
{
ToTable("sys_licenses");
Map(x => x.Licensee).MaxLength(200);
Map(x => x.Modules).MaxLength(400);
}
}
/// Map of to sys_license_activations.
public sealed class LicenseActivationMap : EntityMap
{
/// Creates the map.
public LicenseActivationMap()
{
ToTable("sys_license_activations");
Map(x => x.Action).MaxLength(40);
Map(x => x.Modules).MaxLength(400);
Map(x => x.Outcome).MaxLength(60);
}
}
/// Map of to sys_data_protection_keys.
public sealed class DataProtectionKeyMap : EntityMap
{
/// Creates the map.
public DataProtectionKeyMap()
{
ToTable("sys_data_protection_keys");
Map(x => x.FriendlyName).MaxLength(200);
}
}
/// Map of to sys_log.
public sealed class LogEntryMap : EntityMap
{
/// Creates the map.
public LogEntryMap()
{
ToTable("sys_log");
Map(x => x.Level).MaxLength(20);
Map(x => x.Section).MaxLength(40);
Map(x => x.Source).MaxLength(200);
Map(x => x.UserName).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.TraceId).MaxLength(64);
Map(x => x.Request).MaxLength(400);
Map(x => x.Entity).MaxLength(100);
Map(x => x.EntityId).MaxLength(100);
Map(x => x.Data).Json();
}
}
/// Map of to sys_security_audit.
public sealed class SecurityAuditEntryMap : EntityMap
{
/// Creates the map.
public SecurityAuditEntryMap()
{
ToTable("sys_security_audit");
Map(x => x.Action).MaxLength(100);
Map(x => x.UserName).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.IpAddress).MaxLength(64);
Map(x => x.Target).MaxLength(200);
Map(x => x.Details).Json();
Map(x => x.PreviousHash).MaxLength(64);
Map(x => x.Hash).MaxLength(64);
}
}
/// Map of to sys_scheduled_tasks.
public sealed class ScheduledTaskMap : EntityMap
{
/// Creates the map.
public ScheduledTaskMap()
{
ToTable("sys_scheduled_tasks");
Map(x => x.Code).MaxLength(100);
Map(x => x.Name).MaxLength(200);
Map(x => x.JobType).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.Cron).MaxLength(100);
Map(x => x.TimeZone).MaxLength(64);
Map(x => x.Parameters).Json();
}
}
/// Map of to sys_job_runs.
public sealed class JobRunMap : EntityMap
{
/// Creates the map.
public JobRunMap()
{
ToTable("sys_job_runs");
Map(x => x.TaskCode).MaxLength(100);
Map(x => x.TraceId).MaxLength(64);
}
}
/// Map of to sys_job_locks.
public sealed class JobLockMap : EntityMap
{
/// Creates the map.
public JobLockMap()
{
ToTable("sys_job_locks");
HasKey(x => x.Id, identity: false);
Map(x => x.Id).MaxLength(100);
Map(x => x.Owner).MaxLength(100);
}
}
/// Map of to sys_notifications.
public sealed class SystemNotificationMap : EntityMap
{
/// Creates the map.
public SystemNotificationMap()
{
ToTable("sys_notifications");
NotificationColumns.Configure(this);
}
}
/// Map of to sys_notification_reads.
public sealed class SystemNotificationReadMap : EntityMap
{
/// Creates the map.
public SystemNotificationReadMap() => ToTable("sys_notification_reads");
}
/// The notification columns shared by sys_notifications and notifications.
internal static class NotificationColumns
{
public static void Configure(EntityMap map)
where T : NotificationRecord, new()
{
map.Map(x => x.Category).MaxLength(40);
map.Map(x => x.Title).MaxLength(200);
map.Map(x => x.Link).MaxLength(400);
}
}