This commit is contained in:
2026-11-12 18:50:18 +03:30
parent 9178058173
commit ee40b3e811
3 changed files with 37 additions and 14 deletions
@@ -9,13 +9,20 @@ import type { FanavaranClaimProduct } from "./fanavaran-claim-product";
/**
* Fanavaran dummy licence issue date when `person.driverLicenseDate` is missing.
* Kept recent so hull `IsLicenseReplaced` stays null (see 10-year rule).
* Set well in the past (> 3 years) so the new IsLicenseReplaced logic does not
* force an explicit 0 answer for a missing date, and < 10 years so it stays null.
*/
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1404/08/20";
export const FANAVARAN_DUMMY_LICENCE_ISSU_DATE = "1400/01/01";
/** Years since issue after which hull/third-party "licence replaced?" becomes yes (1). */
export const FANAVARAN_LICENCE_REPLACED_AFTER_YEARS = 10;
/**
* Years since issue below which Fanavaran requires an explicit 0/1 answer
* for IsLicenseReplaced (rule: GovahiTamdidiMustBeRequiredWhenGovahiSodurDateYearIsLessThreeRule).
*/
export const FANAVARAN_LICENCE_REPLACED_REQUIRED_WITHIN_YEARS = 3;
/**
* True when `issueDate` is more than `years` before `referenceDate` (Jalali).
* Used for Fanavaran IsLicenseReplaced / IsLicenseReplacement.
@@ -40,20 +47,36 @@ export function isJalaliDateOlderThanYears(
/**
* Hull `IsLicenseReplaced` / ثالث `IsLicenseReplacement`:
* - licence issue more than 10 years before accident → `1`
* - otherwise → `null` (never send `0`)
* - licence issued more than 10 years before accident → `1` (replaced)
* - licence issued less than 3 years before accident → `0` (not replaced, but
* Fanavaran rule GovahiTamdidiMustBeRequiredWhenGovahiSodurDateYearIsLessThreeRule
* requires an explicit answer, never null)
* - 3–10 years → `null` (field is optional in this range)
*/
export function resolveFanavaranIsLicenseReplaced(
licenceIssuDate: unknown,
accidentDate: unknown,
): 1 | null {
return isJalaliDateOlderThanYears(
licenceIssuDate,
accidentDate,
FANAVARAN_LICENCE_REPLACED_AFTER_YEARS,
)
? 1
: null;
): 1 | 0 | null {
if (
isJalaliDateOlderThanYears(
licenceIssuDate,
accidentDate,
FANAVARAN_LICENCE_REPLACED_AFTER_YEARS,
)
) {
return 1;
}
// Newer than 3 years: Fanavaran requires explicit 0.
if (
!isJalaliDateOlderThanYears(
licenceIssuDate,
accidentDate,
FANAVARAN_LICENCE_REPLACED_REQUIRED_WITHIN_YEARS,
)
) {
return 0;
}
return null;
}
export type FanavaranRoleIdentity = {