using System.Text.Json.Serialization;
namespace NTP.Application.Grains.Registry;
// ------------------------------------------------------------------ shared / lookups
/// Who the caller is, as far as the registry rules care (legacy session.stkid / companycodeno / userrolecode).
public sealed record RegistryScope(bool CompanyOnly, long? CompanyCodeNo, bool IsGoo);
public sealed class RegistryPermissionsDto
{
public bool IsBadiyaCompany { get; set; }
public bool IsCompanyUser { get; set; }
public long? CompanyCodeNo { get; set; }
public bool CanAddTruck { get; set; }
public bool CanAddTrailer { get; set; }
public bool CanAddDriver { get; set; }
public bool CanEditTruck { get; set; }
public bool CanEditTrailer { get; set; }
public bool CanRevokeTruck { get; set; }
public bool CanRevokeTrailer { get; set; }
public bool CanRevokeDriver { get; set; }
public bool CanAcceptTruck { get; set; }
public bool CanAcceptTrailer { get; set; }
public bool CanAcceptDriver { get; set; }
/// Action 107: pick / see destinations (truck form, company 327 only).
public bool CanManageDestinations { get; set; }
/// Roles GTO, GOO, GNAC may export the truck report (legacy report icon).
public bool CanExportTruckReport { get; set; }
public bool CanExportDriverReport { get; set; }
public bool CanCancelBlacklist { get; set; }
}
public sealed class RegistryOptionDto
{
public string Value { get; set; } = string.Empty;
public string Label { get; set; } = string.Empty;
}
public sealed class TenderCompanyDto
{
public long Scac { get; set; }
public string? Name { get; set; }
}
public sealed class TruckKindDto
{
/// TRUCKKINDS.TRUCKKINDCODE: S (single), T (tractor head), HTR (half trailer), TR (trailer).
public string Kind { get; set; } = string.Empty;
/// TRUCKKINDS.ID: stored in AXIALS.
public long Id { get; set; }
public string? Name { get; set; }
}
public sealed class RegistryLocationDto
{
public long Id { get; set; }
public string? Name { get; set; }
}
public sealed class RegistryNationalityDto
{
public string Code { get; set; } = string.Empty;
public string? Name { get; set; }
}
public sealed class RegistryDestinationOptionsDto
{
/// gn_type PCKD (legacy "مشول").
public IReadOnlyList Packed { get; set; } = [];
/// gn_type BULK (legacy "سائب").
public IReadOnlyList Bulk { get; set; } = [];
/// gn_type BULK_GALLAB (legacy "سائب - قلابات").
public IReadOnlyList BulkGallab { get; set; } = [];
}
public sealed class RegistryAttachmentDto
{
public string FileName { get; set; } = string.Empty;
public string OriginalName { get; set; } = string.Empty;
/// truck | trailer | driver (route segment of the download endpoint).
public string Kind { get; set; } = string.Empty;
}
public sealed record RegistryTempFileDto(string Id, string Name, long Size);
public sealed record RegistryDownload(Stream Content, string ContentType, string FileName);
/// Result of a write: message is shown verbatim by the front end (legacy Arabic MSG).
public sealed record RegistryResult(string Message, long? Id = null);
// ------------------------------------------------------------------ list queries
public sealed record TruckListQuery(string? SearchType, string? Tn, string? ChasesNumber, string? StatusCode, string? HeadType, long? Tcscac);
public sealed record TrailerListQuery(string? Tn, string? ChasesNumber, string? StatusCode, long? Tcscac);
public sealed record DriverListQuery(string? Nnpn, string? Name, string? StatusCode);
public sealed record BlacklistQuery(string? EntityId, string? Category, string? StatusCode);
public sealed class TruckGridRowDto
{
public long Id { get; set; }
public string Tn { get; set; } = string.Empty;
/// TN (truck) or TRN (trailer) - what the row represents.
public string EntityType { get; set; } = "TN";
public string? ChasesNumber { get; set; }
public DateTime? CreateTimestamp { get; set; }
public DateTime? RegDate { get; set; }
public string? CreateUserId { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? CompName { get; set; }
/// For trailer rows: the connected truck id (NTP_TRAILERS.TN_ID).
public long? TnId { get; set; }
}
public sealed class TrailerGridRowDto
{
public long Id { get; set; }
public string Tn { get; set; } = string.Empty;
public string? ChasesNumber { get; set; }
public DateTime? CreateTimestamp { get; set; }
public DateTime? RegDate { get; set; }
public string? CreateUserId { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? CompName { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
}
public sealed class DriverGridRowDto
{
public long Id { get; set; }
public string Nnpn { get; set; } = string.Empty;
public string? Name { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public DateTime? CreateTimestamp { get; set; }
public string? CreateUserId { get; set; }
public string? CompName { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
}
public sealed class BlacklistGridRowDto
{
public long Id { get; set; }
public string? Category { get; set; }
public string? CategoryCaption { get; set; }
public string? EntityType { get; set; }
public string? EntityTypeCaption { get; set; }
/// Permit number for PERMIT entries, the raw number for driver/truck/trailer entries.
public string? EntityNumber { get; set; }
public DateTime? CreationDate { get; set; }
public string? CreatedBy { get; set; }
public DateTime? LastUpdateDate { get; set; }
public string? LastUpdateUser { get; set; }
public DateTime? ExpiryDate { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? Remarks { get; set; }
}
// ------------------------------------------------------------------ details
public sealed class PendingDestinationDto
{
public string? User { get; set; }
public string? Time { get; set; }
}
public sealed class TruckDetailDto
{
public long Id { get; set; }
public string Tn { get; set; } = string.Empty;
public string? ChasesNumber { get; set; }
public DateTime? RegDate { get; set; }
public long? Axials { get; set; }
/// S when AXIALS < 7, otherwise T (legacy form radio).
public string? AxialsKind { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
public string? Color { get; set; }
public string? Model { get; set; }
public string? ManifactureYear { get; set; }
public string? PhoneNumber { get; set; }
public string? HeadType { get; set; }
public long? Tcscac { get; set; }
public string? CompName { get; set; }
public string? LastUpdateUserId { get; set; }
public DateTime? LastUpdateTimestamp { get; set; }
public long? TrailerId { get; set; }
public string? TrailerTn { get; set; }
/// Active destination location ids (only for users who may see destinations: action 107 or role GOO).
public IReadOnlyList? DestinationIds { get; set; }
public PendingDestinationDto? PendingDestination { get; set; }
public IReadOnlyList Attachments { get; set; } = [];
}
public sealed class TrailerDetailDto
{
public long Id { get; set; }
public string Tn { get; set; } = string.Empty;
public string? ChasesNumber { get; set; }
public DateTime? RegDate { get; set; }
public long? Axials { get; set; }
/// TR when AXIALS < 12, otherwise HTR (legacy form radio).
public string? AxialsKind { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
public string? PhoneNumber { get; set; }
public long? TruckId { get; set; }
public long? Tcscac { get; set; }
public string? CompName { get; set; }
public IReadOnlyList Attachments { get; set; } = [];
}
public sealed class DriverDetailDto
{
public long Id { get; set; }
public string Nnpn { get; set; } = string.Empty;
public string? Name { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public string StatusCode { get; set; } = string.Empty;
public string? StatusCaption { get; set; }
public string? Nat { get; set; }
public string? Cat { get; set; }
public string? Mobile1 { get; set; }
public string? Mobile2 { get; set; }
/// Owning company (used for the company-user scope check only).
[JsonIgnore]
public long? Tcscac { get; set; }
public IReadOnlyList Attachments { get; set; } = [];
}
// ------------------------------------------------------------------ requests
/// Destinations picked on the truck form (location ids per group).
public sealed class TruckDestinationsRequest
{
public List Packed { get; set; } = [];
public List Bulk { get; set; } = [];
public List BulkGallab { get; set; } = [];
public IReadOnlyList All() => [.. Packed, .. Bulk, .. BulkGallab];
}
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class SaveTruckRequest
{
public string? Tn { get; set; }
public string? ChasesNumber { get; set; }
public long? Axials { get; set; }
public DateTime? RegDate { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
public string? Color { get; set; }
public string? Model { get; set; }
public string? ManifactureYear { get; set; }
public string? PhoneNumber { get; set; }
public string? HeadType { get; set; }
public long? Tcscac { get; set; }
/// Temp ids returned by POST files/temp.
public List? AttachmentIds { get; set; }
/// Only honoured for users with action 107. On update: null = leave destinations untouched.
public TruckDestinationsRequest? Destinations { get; set; }
}
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class SaveTrailerRequest
{
public string? Tn { get; set; }
public string? ChasesNumber { get; set; }
public long? Axials { get; set; }
public DateTime? RegDate { get; set; }
public string? OwnerName { get; set; }
public string? OwnerNnpn { get; set; }
public string? PhoneNumber { get; set; }
public long? Tcscac { get; set; }
/// The truck to connect the trailer to (legacy TNID). Optional.
public long? TruckId { get; set; }
public List? AttachmentIds { get; set; }
}
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class SaveDriverRequest
{
public string? Nnpn { get; set; }
public string? Name { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public string? Nat { get; set; }
public string? Cat { get; set; }
public string? Mobile1 { get; set; }
public string? Mobile2 { get; set; }
public List? AttachmentIds { get; set; }
}
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class AddBlacklistRequest
{
/// PERMIT (default, the only value the legacy page sends), DRIVERNUMBER, TRUCKNUMBER, TRAILERNUMBER.
public string? EntityType { get; set; }
/// Permit number (PN), or the permit id when ; the number for the other entity types.
public string? EntityNum { get; set; }
public bool IsId { get; set; }
public string? Category { get; set; }
/// Number of days (legacy EXPIRYDATE select: 1,2,3,4,5,10,14,30).
public int ExpiryDays { get; set; }
public string? Remarks { get; set; }
}
public sealed class CancelBlacklistRequest
{
public string? Remarks { get; set; }
}
public sealed record BlacklistAddedDto(string Message, long BlacklistId, DateTime ExpiryDate);
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class SaveWeighbridgeControlRequest
{
public string? Tn { get; set; }
public long? LocationId { get; set; }
public string? Notes { get; set; }
public DateTime? ExpiryDate { get; set; }
}
public sealed class SaveGrainsWeightsRequest
{
public string? Pn { get; set; }
public string? EmptyWeight { get; set; }
public string? GrossWeight { get; set; }
public string? DocumentNumber { get; set; }
}
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public sealed class FleetCheckRequest
{
public long Tn { get; set; }
public long Scac { get; set; }
}
public sealed record FleetCheckResult(bool Allowed, string? Message, int TotalFleet, int Turn);
// ------------------------------------------------------------------ permit-screen lookups (grains.cfc)
public sealed class LocationTruckCountDto
{
public string? Loc { get; set; }
public long Cnt { get; set; }
}
public sealed class DriverFromPermitDto
{
public string? Drvr { get; set; }
public string? Cat { get; set; }
public DateTime? Dled { get; set; }
public string? Dln { get; set; }
public string? Nat { get; set; }
}
public sealed class TruckFromPermitDto
{
public string? Tn { get; set; }
public string? Trn { get; set; }
public string? Trnat { get; set; }
public string? Tt { get; set; }
public string? Drvr { get; set; }
public string? Cat { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
public string? Nat { get; set; }
public string? Nnpn { get; set; }
public long? RoutingTemplateId { get; set; }
public long? OriginAddressId { get; set; }
public long? DestinationAddressId { get; set; }
public string? Firms { get; set; }
public string? Asrn { get; set; }
public string? Can { get; set; }
public string? CanName { get; set; }
}
public sealed class TrailerInUseDto
{
public string? Pn { get; set; }
public string? CreationDate { get; set; }
}
public sealed class PermitByTruckDto
{
public long Id { get; set; }
public string? Drvr { get; set; }
public string? Tn { get; set; }
public string? Pn { get; set; }
public string? ShipmentStatusCode { get; set; }
}
public sealed class TruckInfoForPermitDto
{
public string? Message { get; set; }
public bool CloseModal { get; set; }
public string? Tn { get; set; }
public string? ChasesNumber { get; set; }
public string? Axials { get; set; }
public DateTime? RegDate { get; set; }
}
public sealed class TrailerInfoForPermitDto
{
public string? Message { get; set; }
public string? ChasesNumber { get; set; }
public string? Axials { get; set; }
public DateTime? RegDate { get; set; }
}
public sealed class DriverInfoForPermitDto
{
public string? Name { get; set; }
public string? Dln { get; set; }
public DateTime? Dled { get; set; }
}
public sealed class TrailerOfTruckDto
{
public long TrailerId { get; set; }
public string? TrailerNumber { get; set; }
}