protected override bool If(CoverageRulesContainer fact)
        {
            if (!this.RuleApplies(fact) || base.RuleApplies(fact))
                return false;

            return Evaluate(fact);
        }
 // POST api/coveragevalidation
 public CoverageValidation.Model.Resource.Validation.CoverageValidationResponse Post(CoverageValidation.Model.Resource.Validation.CoverageValidationRequest request)
 {
     var ruleOutput = new CoverageValidationResponse();
     var container = new CoverageRulesContainer(request, ruleOutput);
     RuleManager.Execute(container);
     return container.Response;
 }
        protected override void Then(CoverageRulesContainer fact)
        {
            //Take the messages and move them to the result object using the comparer again
            foreach (var message in Messages)
            {

            }
        }
        public static void Execute(CoverageRulesContainer fact)
        {
            //First execute the policy level rules.
              var ruleset = new CoverageRuleSet();
              ruleset.Execute(fact);

              //Execute the vehicle rules.
              ExecuteVehicleRules(fact);
        }
        public override bool Evaluate(CoverageRulesContainer fact)
        {
            var rRIsCarried = RR.Comparer()(fact);
            var comprehensiveIsNotCarried = !COMP.Comparer()(fact);

            if (rRIsCarried && comprehensiveIsNotCarried)
            {
                return true;
            }
            return false;
        }
        public override bool Evaluate(CoverageRulesContainer fact)
        {
            var CB_Radio_Car_Phone_coverage_is_carried = CB.Comparer()(fact);
            var ComprehensiveIsNotCarried = !COMP.Comparer()(fact);
            var Combined_AdditionalIsNotCarried = !COMB.Comparer()(fact);

            if (CB_Radio_Car_Phone_coverage_is_carried && (ComprehensiveIsNotCarried || Combined_AdditionalIsNotCarried))
            {
                return true;
            }
            return false;
        }
        public override bool Evaluate(CoverageRulesContainer fact)
        {
            var coverageA = GetCoverage(fact, BINOtCarriedAndCOLIsNotCared.CoverageAMnemonic);
            var coverageB = GetCoverage(fact, BINOtCarriedAndCOLIsNotCared.CoverageBMnemonic);
            var bINOtCarriedAndCOLIsNotCared = BINOtCarriedAndCOLIsNotCared.Compare(fact);

            var anyOfTHeFollowingAreCarried = AnyOfTHeFollowingAreCarried.Comparer()(fact.Request.Coverages);

            if (bINOtCarriedAndCOLIsNotCared && anyOfTHeFollowingAreCarried)
            {
                return true;
            }
            return false;
        }
        public override bool Evaluate(CoverageRulesContainer fact)
        {
            var ruleIsTrue = false;
            foreach (var vehicleFact in fact.Request.Coverages)
            {
                if (!base.RuleApplies(fact)) continue;

                //Should really be a vehicle rule set
                var coverageA = GetCoverage(fact, comparer.CoverageAMnemonic);
                var coverageB = GetCoverage(fact, comparer.CoverageAMnemonic);

                if (!comparer.Compare(fact))
                {
                    //Add to the message list or some kind of object to store to eventually add to the result.
                    ruleIsTrue = true;
                    Messages.Add("There is an issue");
                }
            }

            return ruleIsTrue;
        }
        private static void ExecuteVehicleRules(CoverageRulesContainer fact)
        {
            //Since all the coverages come in a single list they need to be put into groups since they are evaluated per vehicle.
              var coveragesByVehicle = new Dictionary<VehicleInfo, List<Model.Resource.Coverage>>();

              foreach (var vehicle in fact.Request.Vehicles)
              {
              //Get the coverages for this vehicle
              var coverages = fact.Request.Coverages.Where(c => c.VehicleId == vehicle.Id).ToList();

              //Add the vehicle and the coverages to the dictionary
              coveragesByVehicle.Add(vehicle, coverages);
              }

              var ruleset = new CoverageVehicleRuleSet();

              //Now loop through all then vehicles and validate the coverages
              foreach (var item in coveragesByVehicle)
              {
              var request = new VehicleCoverageRequest()
              {
                  Coverages = item.Value,
                  Drivers = fact.Request.Drivers,
                  RiskState = fact.Request.RiskState,
                  Vehicle = item.Key,
                  Parent = fact.Request
              };

              var response = new VehicleCoverageResponse();
              var container = new VehicleCoverageRulesContainer(request, response);

              ruleset.Execute(container);

              //Need to put the results back into the original container
              fact.Response.Messages.AddRange(container.Response.Messages);

              }
        }
 public override bool Evaluate(CoverageRulesContainer fact)
 {
     return comparer.Compare(fact);
 }
 //Will need some way to remember what happens from the Evaluate to the Then
 //Most likely the evaluate will set up the return message.
 protected override void Then(CoverageRulesContainer fact)
 {
     throw new System.NotImplementedException();
 }
 public abstract bool Compare(CoverageRulesContainer coverages);
 public override bool Compare(CoverageRulesContainer fact)
 {
     return base.Compare((a, b) => fact1.Comparer()(fact) && fact2.Comparer()(fact));
 }