private static FundingStreamPeriodProfilePattern LoadFSPConfiguration(string providerIdentifier, string fundingStreamPeriod)
        {
            // Get Provider Profile Pattern for an FSP, if not get for FS for the provider
            // if not available then get one for FSP

            FundingStreamPeriodProfilePattern pattern = FromCofigGetProviderFspProfilePattern(providerIdentifier, fundingStreamPeriod);

            return(pattern ?? FromCofigGetFspProfilePattern(fundingStreamPeriod));
        }
        public static string GetGenericResponse(Request request, TraceWriter log)
        {
            FundingStreamPeriodProfilePattern fspPattern = LoadFSPConfiguration(request.AllocationOrganisation.AlternateOrganisation.Identifier,
                                                                                request.FundingStreamPeriod
                                                                                );

            //Three types of profiling:
            //Profile/Re-profile with balancing payment calc , don't change past periods (ReProfilePastPeriods =false, e.g. PE Sport and Premium, DSG)
            //Profile/Re-profile with no balancing payment calc, don't change past periods (ReProfilePastPeriods =false, e.g. 16-19 funding)
            //Profile/Re-Profile wiith no balancing payment calc, change past periods (e.g. SFA type of funding)
            if (IsReProfilingWithoutBalancingPayment(request.LastApprovedProfilePeriods != null, fspPattern.ReProfilePastPeriods, fspPattern.CalculateBalancingPayment))
            {
                return(GetReProfileResponse(request, fspPattern.ProfilePattern));
            }


            return(GetReponseForAnyDistributionPattern(request, fspPattern));
        }
        private static string GetReponseForAnyDistributionPattern(Request req, FundingStreamPeriodProfilePattern fspPattern)
        {
            DateBoundaries dateBoundaries = GetDateBoundariesOfAllocation(req.AllocationStartDate, req.AllocationEndDate, fspPattern.FundingStreamPeriodStartDate, fspPattern.FundingStreamPeriodEndDate);

            List <AllocationProfilePeriod> profilePeriods = GetProfiledAllocationPeriodsWithPatternApplied(dateBoundaries.StartDate, dateBoundaries.EndDate, req.AllocationValuesByDistributionPeriod, fspPattern.ProfilePattern);

            List <AllocationProfilePeriod> resultProfilePeriods = profilePeriods;

            if (fspPattern.CalculateBalancingPayment)
            {
                resultProfilePeriods = GetAllocationProfilePeriodsWithBalancingPaymentApplied(req.CalculationDate, profilePeriods, req.LastApprovedProfilePeriods, fspPattern.ProfilePattern);
            }

            var myObj = new
            {
                AllocationOrganisation = req.AllocationOrganisation,
                FundingStreamPeriod    = req.FundingStreamPeriod,
                AllocationValuesByDistributionPeriod = req.AllocationValuesByDistributionPeriod,
                ProfilePeriods = resultProfilePeriods
            };

            return(JsonConvert.SerializeObject(myObj));
        }