"""Fictional cutover model. Run alongside cutover-case.json with Python 3."""
from decimal import Decimal, ROUND_HALF_UP
from pathlib import Path
import json
D=lambda x:Decimal(str(x))
c=json.loads(Path(__file__).with_name('ukeorproviderreview-cutover-case.json').read_text())
monthly=((D(c['annual_salary_each'])+D(c['annual_employer_NI_each'])+D(c['annual_employer_pension_each']))*c['employees']/12+D(c['assumed_monthly_fee_each'])*c['employees']).quantize(D('.01'),rounding=ROUND_HALF_UP)
def release(records_accepted, legal_ready, cleared_cash, due, promised_refund=0, old_platform_credit=0):
    # Neither promised refund nor a credit held elsewhere funds this bank account.
    return records_accepted and legal_ready and D(cleared_cash)>=D(due)
def shortfall(cash,due):return max(D(0),D(due)-D(cash))
remaining=D(c['opening_cash'])-monthly
topup=shortfall(remaining,monthly)
checks={
 'monthly_envelope': monthly==D('31382.88'),
 'on_time':release(True,True,40000,monthly),
 'missing_pension_field_blocks':not release(False,True,40000,monthly),
 'legal_readiness_blocks':not release(True,False,40000,monthly),
 'accepted_data_insufficient_cash':not release(True,True,remaining,monthly),
 'promised_refund_not_cash':not release(True,True,remaining,monthly,promised_refund=25000),
 'old_platform_credit_not_cash':not release(True,True,remaining,monthly,old_platform_credit=25000),
 'cleared_topup_releases':release(True,True,remaining+topup,monthly),
 'one_penny_short_blocks':not release(True,True,monthly-D('.01'),monthly),
 'delay_topup':topup==D('22765.76'),
 'late_refund_reconciles':c['late_refund']+c['late_final_adjustment']==c['outgoing_deposit'],
 'single_hire_budget':D(60000)+D(8250)+D('1320.90')+D(479)*12==D('75318.90')}
assert all(checks.values()),checks
print(json.dumps({'model':'cutover-v1','monthly':str(monthly),'after_first_funding':str(remaining),'delayed_topup':str(topup),'checks':checks},indent=2))
