namespace NTP.Application.Registrar;
/// The three registrations a company registers from the mobile app and the registrar reviews (legacy entities DRIVERINFO, TRUCKINFO, TRAILERINFO).
public enum RegistrarKind
{
Driver,
Truck,
Trailer,
}
/// Row of DRIVERS_INFO / TRUCKS_INFO / TRAILERS_INFO. One class for the three tables (columns a table does not have stay null). Settable properties: Dapper + Oracle NUMBER.
public class RegistrarRecord
{
public long Id { get; set; }
public string? StatusCode { get; set; }
/// TN (truck) / TRN (trailer); empty for a driver.
public string? PlateNo { get; set; }
/// TN_CODE / TRN_CODE: the code of a foreign plate.
public string? PlateCode { get; set; }
public string? Nationality { get; set; }
// driver
public string? Nnpn { get; set; }
public string? NameAr { get; set; }
public string? NameEn { get; set; }
public DateTime? DateOfBirth { get; set; }
public string? BloodGroup { get; set; }
public string? Address { get; set; }
public string? LicenseType { get; set; }
public DateTime? LicenseIssueDate { get; set; }
public string? Mobile { get; set; }
// licence (all three)
public string? LicenseNo { get; set; }
public DateTime? LicenseExpiryDate { get; set; }
// truck / trailer
public string? LicenseRegistrationNo { get; set; }
public string? Manufacturer { get; set; }
public long? ManufactureYear { get; set; }
/// TRUCK_TYPE / TRAILER_TYPE.
public string? VehicleType { get; set; }
/// TRUCK_CATEGORY / TRAILER_CATEGORY (صفة الاستعمال).
public string? Category { get; set; }
public string? Color { get; set; }
public string? SecondaryColor { get; set; }
public string? Model { get; set; }
public string? VinNumber { get; set; }
public string? EngineNumber { get; set; }
public decimal? LoadingWeight { get; set; }
public decimal? GrossWeight { get; set; }
/// GROSS_WEIGHT - LOADING_WEIGHT (the view column EMPTY_WEIGHT of TRUCK_INFO_VIEW); trucks only.
public decimal? EmptyWeight { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
public long? OwnerPhoneNumber { get; set; }
public string? OwnerAddress { get; set; }
public string? Governate { get; set; }
public string? Notes { get; set; }
public string? RevokeReason { get; set; }
public string? CreatedBy { get; set; }
public DateTime? CreationDate { get; set; }
public string? UpdatedBy { get; set; }
public DateTime? LastUpdateDate { get; set; }
}
///
/// Grid filters. is the NNPN (drivers), TN (trucks) or TRN (trailers); equal, case-insensitive. (drivers, Arabic name) and
/// (trucks / trailers) are "contains". empty = every status.
///
public sealed record RegistrarQuery(
string? Number, string? LicenseNo, string? Name, string? OwnerName, string? VinNumber,
DateTime? DateFrom, DateTime? DateTo, IReadOnlyList StatusCodes);
/// The update form (legacy *InfoForm). Fields a kind does not have are ignored. Year and weights come as text, like the legacy digits-only check.
public sealed class RegistrarUpdateRequest
{
public string? Nationality { get; set; }
public string? PlateNo { get; set; }
public string? PlateCode { get; set; }
public string? Nnpn { get; set; }
public string? NameAr { get; set; }
public string? NameEn { get; set; }
public string? Mobile { get; set; }
public DateTime? DateOfBirth { get; set; }
public string? BloodGroup { get; set; }
public string? Governate { get; set; }
public string? Address { get; set; }
public string? LicenseNo { get; set; }
public string? LicenseType { get; set; }
public DateTime? LicenseIssueDate { get; set; }
public DateTime? LicenseExpiryDate { get; set; }
public string? LicenseRegistrationNo { get; set; }
public string? OwnerName { get; set; }
public string? OwnerAddress { get; set; }
public string? Manufacturer { get; set; }
public string? Model { get; set; }
public string? Color { get; set; }
public string? SecondaryColor { get; set; }
public string? VehicleType { get; set; }
public string? ManufactureYear { get; set; }
public string? Category { get; set; }
public string? VinNumber { get; set; }
public string? EngineNumber { get; set; }
public string? LoadingWeight { get; set; }
public string? GrossWeight { get; set; }
public string? Notes { get; set; }
}
public sealed record RegistrarRevokeRequest(string? Reason);
/// What the caller may do with one record in its current status (the legacy PORTLET buttons, decided by STATUS_ACTION_MATRIX).
public sealed record RegistrarActions(bool Update, bool Complete, bool Revoke, bool Reopen);
/// An image or file of the registration (table ATTACHMENTS, entity DRIVERINFO / TRUCKINFO / TRAILERINFO). The content is served by the API (GET {id}/attachments/{attachmentId}).
public sealed record RegistrarAttachment(long Id, string FileName);
/// The bytes of one attachment, fetched from the host where the mobile app stored it.
public sealed record RegistrarFile(byte[] Content, string ContentType, string FileName);
public sealed record RegistrarDetail(RegistrarRecord Record, IReadOnlyList Attachments, RegistrarActions Actions);
public sealed record RegistrarResult(string Message);
public sealed record LookupItem(string Code, string Ar, string En);
/// The drop-down lists of the three forms, by list name (legacy LT_PUBLIC lookups and NATIONALITY).
public sealed record RegistrarLookups(IReadOnlyDictionary> Lists);
public static class RegistrarStatus
{
public const string Pending = "PENDING";
public const string Completed = "COMPLETED";
public const string Revoke = "REVOKE";
public const string Incomplete = "INCOMPLETE";
}
/// Per kind: URL slug, table, entity name of the attachments and the permission keys.
public sealed record RegistrarKindInfo(
RegistrarKind Kind, string Slug, string Table, string Entity, string NotificationType, string NotificationNumber,
string Screen, string Update, string? UpdateCompleted, string Complete, string Revoke, string Reopen, string Report);
public static class RegistrarKinds
{
private static readonly RegistrarKindInfo[] All =
[
new(RegistrarKind.Driver, "drivers", "DRIVERS_INFO", "DRIVERINFO", "سائق", "NNPN",
Access.PermissionKeys.RegistrarDrivers, Access.PermissionKeys.RegistrarDriversUpdate, Access.PermissionKeys.RegistrarDriversUpdateCompleted,
Access.PermissionKeys.RegistrarDriversComplete, Access.PermissionKeys.RegistrarDriversRevoke, Access.PermissionKeys.RegistrarDriversReopen,
Access.PermissionKeys.RegistrarDriversReport),
new(RegistrarKind.Truck, "trucks", "TRUCKS_INFO", "TRUCKINFO", "شاحنة", "TN",
Access.PermissionKeys.RegistrarTrucks, Access.PermissionKeys.RegistrarTrucksUpdate, null,
Access.PermissionKeys.RegistrarTrucksComplete, Access.PermissionKeys.RegistrarTrucksRevoke, Access.PermissionKeys.RegistrarTrucksReopen,
Access.PermissionKeys.RegistrarTrucksReport),
new(RegistrarKind.Trailer, "trailers", "TRAILERS_INFO", "TRAILERINFO", "مقطوره", "TRN",
Access.PermissionKeys.RegistrarTrailers, Access.PermissionKeys.RegistrarTrailersUpdate, null,
Access.PermissionKeys.RegistrarTrailersComplete, Access.PermissionKeys.RegistrarTrailersRevoke, Access.PermissionKeys.RegistrarTrailersReopen,
Access.PermissionKeys.RegistrarTrailersReport),
];
public static RegistrarKindInfo Of(RegistrarKind kind) => All[(int)kind];
public static bool TryParse(string? slug, out RegistrarKind kind)
{
var hit = All.FirstOrDefault(k => string.Equals(k.Slug, slug, StringComparison.OrdinalIgnoreCase));
kind = hit?.Kind ?? default;
return hit is not null;
}
}