diff --git a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs index 75fe74f..2204134 100644 --- a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs +++ b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/FundingCalculator.cs @@ -209,7 +209,11 @@ public async Task CalculateAsync() .NextValidator(new MustHaveValidApplicationStatusRule()) .NextValidator(new MustHaveValidOwnershipTypeRule()) .NextValidator(new MustHaveValidLicenceRule()) - .NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule()); + .NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule()) + .NextValidator(new MustHaveAtLeastOneOperationalSpaceRule()) + .NextValidator(new MustHaveWeeksInOperationRule()) + .NextValidator(new MustHaveHoursOfOperationRule()) + .NextValidator(new MustHaveDaysOfWeekRule()); try { fundingRules.Validate(_funding); diff --git a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs index ed66927..e06c139 100644 --- a/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs +++ b/OFM.Infrastructure.WebAPI/Services/Processes/Fundings/IFundingValidator.cs @@ -202,6 +202,126 @@ public bool Validate(Funding funding) return true; } + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveAtLeastOneOperationalSpaceRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var operationalSpaces = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && (licDetail.ofm_operational_spaces + < 1 || licDetail.ofm_operational_spaces == null)).Count(); + + if (operationalSpaces > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Operational Spaces.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveWeeksInOperationRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var weeksInOperation = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && (licDetail.ofm_weeks_in_operation + < 1 || licDetail.ofm_weeks_in_operation == null)).Count(); + + if (weeksInOperation > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Weeks in Operation.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveHoursOfOperationRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var operationHoursFrom = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_from + == null).Count(); + var operationHoursTo = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_to + == null).Count(); + + if (operationHoursFrom > 0 || operationHoursTo > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Operation Hours.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + + public IFundingValidator NextValidator(IFundingValidator? next) + { + _next = next; + return next; + } +} + +public class MustHaveDaysOfWeekRule : IFundingValidator +{ + private IFundingValidator? _next; + + public bool Validate(Funding funding) + { + var weekDays = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld + .ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode + == ofm_licence_detail_StatusCode.Active && licDetail.ofm_week_days + == null).Count(); + + if (weekDays > 0) + { + throw new ValidationException( + new ValidationResult("The Service Delivery Details must have valid Week Days when the ChildCare is operating.", ["Service Delivery Details"]), null, null); + } + + _next?.Validate(funding); + + return true; + } + public IFundingValidator NextValidator(IFundingValidator? next) { _next = next;