import type { AllFeatures } from './features';
import { type HeadlineResults } from './headlineResults';
import { type TradingSummaries } from './tradingSummaries';
/**
 * Calculates feature-specific shortfall (for hedgerows and watercourses)
 * Corresponds to cells F14 and F15 logic in the Unit Shortfall sheet
 *
 * Original formula (hedgerow example, but same for watercourses):
 * IF((G147*-1)<G4, G4, IF(G4<=0, (G147*-1), IF(G4>=F4-E4, (G147*-1), (G147*-1)+G4)))
 *
 * Formula pattern:
 * hedgerowFinalLosses = G147
 * deficit = G4
 * requiredGap = F4-E4
 * IF(
 *     -hedgerowFinalLosses < deficit,
 *     deficit,
 *     IF(
 *         deficit<=0,
 *         -hedgerowFinalLosses,
 *         IF(
 *             deficit >= requiredGap,
 *             -hedgerowFinalLosses,
 *             -hedgerowFinalLosses + deficit
 *         )
 *     )
 * )
 */
export declare function featureShortfall(finalLosses: number, deficit: number, requiredGap: number): number;
/**
 * Calculates A1 tier balancing shortfall (the most complex tier)
 * Corresponds to cell F9 logic in the Unit Shortfall sheet
 *
 * A1 is the "balancing tier" that absorbs whatever shortfall remains
 * after higher tiers (A5-A2) have been accounted for
 *
 * Original formula:
 * =IFERROR(IF(OR('Trading Summary Area Habitats'!$K$13<0,'Trading Summary WaterC''s'!$I$13<0),"ERROR", IF((F13+F12+F11+F10+((H65+M122+G138)*-1))>=G3, ((H65+M122+G138)*-1), IF((F13+F12+F11+F10+((H65+M122+G138)*-1))>=(G3-(F3-E3)), (((H65+M122+G138)*-1)+(G3-(F13+F12+F11+F10+((H65+M122+G138)*-1)))), IF(G3<=0,((H65+M122+G138)*-1), IF((F13+F12+F11+F10+((H65+M122+G138)*-1))<G3,(G3-(F10+F11+F12+F13)), IF(G3>=F3-E3, ((H65+M122+G138)*-1)+(F3-E3), ((H65+M122+G138)*-1)+G3)))))),"Error")
 *
 * Cleaned formula:
 *
 * IF(
 *   OR(
 *     'Trading Summary Area Habitats'!$K$13<0,
 *     'Trading Summary WaterC''s'!$I$13<0
 *   ),
 *   "ERROR",
 *   IF(
 *     (
 *       F13+F12+F11+F10
 *       +((H65+M122+G138)*-1)
 *       >=G3
 *     ),
 *     (H65+M122+G138)*-1,
 *     IF(
 *       (
 *         F13+F12+F11+F10
 *         +((H65+M122+G138)*-1)
 *         >=G3-(F3-E3)
 *       ),
 *       (
 *         ((H65+M122+G138)*-1)
 *         +(
 *           G3
 *           -(
 *             F13+F12+F11+F10
 *             +(
 *               (H65+M122+G138)*-1
 *              )
 *            )
 *          )
 *        ),
 *        IF(
 *          G3<=0,
 *          ((H65+M122+G138)*-1),
 *          IF(
 *            (
 *              F13+F12+F11+F10
 *              +((H65+M122+G138)*-1)
 *            )<G3,
 *            (G3-(F10+F11+F12+F13)),
 *            IF(
 *              G3>=F3-E3,
 *              ((H65+M122+G138)*-1)+(F3-E3),
 *              ((H65+M122+G138)*-1)+G3
 *            )
 *          )
 *        )
 *      )
 *   )
 * )
 *
 * Annotated formula:
 *
 * a2ToA5Shortfalls = F13+F12+F11+F10
 * allA1Losses = H65+M122+G138
 * habitatUnitDeficit = G3
 * unitGap = (F3 - E3)
 * IF(
 *     a2ToA5Shortfalls - allA1Losses >= habitatUnitDeficit,
 *     -allA1Losses,
 *     IF(
 *         a2ToA5Shortfalls - allA1Losses >= habitatUnitDeficit - unitGap
 *         (
 *             -allA1Losses
 *             + habitatUnitDeficit
 *             - a2ToA5Shortfalls
 *             + allA1Losses
 *         ),
 *         IF(
 *             habitatUnitDeficit<=0,
 *             -allA1Losses,
 *             IF(
 *                 a2ToA5Shortfalls - allA1Losses < habitatUnitDeficit,
 *                 (habitatUnitDeficit - a2ToA5Shortfalls),
 *                 IF(
 *                     habitatUnitDeficit >= unitGap,
 *                     -allA1Losses + unitGap,
 *                     -allA1Losses + habitatUnitDeficit
 *                 )
 *             )
 *         )
 *     )
 * )
 */
export declare function a1BalancingShortfall(headline: HeadlineResults, shortfalls: {
    a2: number;
    a3: number;
    a4: number;
    a5: number;
}, details: ReturnType<typeof buildTierDetail>): number;
/**
 * Builds tier detail arrays with individual habitat/hedgerow/watercourse net changes
 * Used for detailed reporting in Section 3 of the Unit Shortfall sheet
 */
declare function buildTierDetail(features: AllFeatures, tradingSummaries: TradingSummaries): {
    vh: {
        a5: {
            netGains: number;
            netLosses: number;
        };
    };
    high: {
        a5: {
            unitChange: number[];
            lossesInTier: number;
        };
        a4: {
            unitChange: number[];
            lossesInTier: number;
        };
        a3: {
            unitChange: number[];
            lossesInTier: number;
        };
        a2: {
            unitChange: number[];
            lossesInTier: number;
        };
        a1: {
            unitChange: number[];
            lossesInTier: number;
        };
    };
    medium: {
        a1: {
            rule1: number[];
            rule2: number;
            rule3: number;
            rule4: number;
            finalLosses: number;
        };
        a2: {
            rule1: number[];
            rule2: number;
            rule3: number;
            rule4: number;
            finalLosses: number;
        };
        a4: {
            rule1: number[];
            rule2: number;
            rule3: number;
            rule4: number;
            finalLosses: number;
        };
    };
    low: {
        a1: {
            netUnitChange: number;
            unitChangeFollowingOffset: number;
            unitsRemainingAfterRule5: number;
            finalLosses: number;
        };
    };
    hedgerows: {
        finalLosses: number;
    };
    watercourses: {
        finalLosses: number;
    };
};
/**
 * Main unit shortfall calculation function
 * Calculates unit shortfalls by tier with Spatial Risk Multiplier applied
 * Corresponds to the "Unit Shortfall calculations" sheet
 */
export declare function unitShortfall(features: AllFeatures, headline: HeadlineResults, tradingSummaries: TradingSummaries): {
    hasVeryHighLosses: boolean;
    tierShortfalls: {
        habitats: {
            a5: {
                shortfall: number;
                srmShortfall: number;
            };
            a4: {
                shortfall: number;
                srmShortfall: number;
            };
            a3: {
                shortfall: number;
                srmShortfall: number;
            };
            a2: {
                shortfall: number;
                srmShortfall: number;
            };
            a1: {
                shortfall: number;
                srmShortfall: number;
            };
        };
        hedgerows: {
            shortfall: number;
            srmShortfall: number;
        };
        watercourses: {
            shortfall: number;
            srmShortfall: number;
        };
    };
    tierDetail: {
        vh: {
            a5: {
                netGains: number;
                netLosses: number;
            };
        };
        high: {
            a5: {
                unitChange: number[];
                lossesInTier: number;
            };
            a4: {
                unitChange: number[];
                lossesInTier: number;
            };
            a3: {
                unitChange: number[];
                lossesInTier: number;
            };
            a2: {
                unitChange: number[];
                lossesInTier: number;
            };
            a1: {
                unitChange: number[];
                lossesInTier: number;
            };
        };
        medium: {
            a1: {
                rule1: number[];
                rule2: number;
                rule3: number;
                rule4: number;
                finalLosses: number;
            };
            a2: {
                rule1: number[];
                rule2: number;
                rule3: number;
                rule4: number;
                finalLosses: number;
            };
            a4: {
                rule1: number[];
                rule2: number;
                rule3: number;
                rule4: number;
                finalLosses: number;
            };
        };
        low: {
            a1: {
                netUnitChange: number;
                unitChangeFollowingOffset: number;
                unitsRemainingAfterRule5: number;
                finalLosses: number;
            };
        };
        hedgerows: {
            finalLosses: number;
        };
        watercourses: {
            finalLosses: number;
        };
    };
};
export type UnitShortfallResult = ReturnType<typeof unitShortfall>;
export {};
//# sourceMappingURL=unitShortfall.d.ts.map