Module aster.finance.enterprise_lending. Define EnterpriseInfo has companyId, companyName, industry, yearsInBusiness, employeeCount, annualRevenue, revenueGrowthRate, profitMargin. Define FinancialPosition has totalAssets, currentAssets, totalLiabilities, currentLiabilities, equity, cashFlow, outstandingDebt. Define BusinessHistory has previousLoans, defaultCount, latePayments, creditUtilization, largestLoanAmount, relationshipYears. Define LoanApplication has requestedAmount, loanPurpose, termMonths, collateralValue, guarantorCount. Define LendingDecision has approved, approvedAmount, interestRateBps, termMonths, collateralRequired, specialConditions, riskCategory, confidenceScore, reasonCode, detailedAnalysis. Define LiquidityAnalysis has currentRatio, quickRatio, isHealthy, recommendation. Define LeverageAnalysis has debtToEquity, debtToAssets, riskLevel, maxLoanCapacity. Define ProfitabilityAnalysis has returnOnAssets, returnOnEquity, profitabilityGrade, repaymentCapacity. Rule assessLiquidity given position, produce: Let currentRatio be (position.currentAssets times 100) divided by position.currentLiabilities. Let quickRatio be (position.currentAssets times 100) divided by position.currentLiabilities. If currentRatio at least 200 Return LiquidityAnalysis with currentRatio set to currentRatio and quickRatio set to quickRatio and isHealthy set to true and recommendation set to "Excellent liquidity". If currentRatio at least 150 Return LiquidityAnalysis with currentRatio set to currentRatio and quickRatio set to quickRatio and isHealthy set to true and recommendation set to "Good liquidity". If currentRatio at least 100 Return LiquidityAnalysis with currentRatio set to currentRatio and quickRatio set to quickRatio and isHealthy set to true and recommendation set to "Adequate liquidity". Return LiquidityAnalysis with currentRatio set to currentRatio and quickRatio set to quickRatio and isHealthy set to false and recommendation set to "Poor liquidity". Rule assessLeverage given position, produce: If position.equity equals to 0 Return LeverageAnalysis with debtToEquity set to 0 and debtToAssets set to 0 and riskLevel set to "CRITICAL" and maxLoanCapacity set to 0. Let debtToEquity be (position.totalLiabilities times 100) divided by position.equity. Let debtToAssets be (position.totalLiabilities times 100) divided by position.totalAssets. Let baseCapacity be position.equity times 3. If debtToEquity at most 100 Return LeverageAnalysis with debtToEquity set to debtToEquity and debtToAssets set to debtToAssets and riskLevel set to "LOW" and maxLoanCapacity set to baseCapacity. If debtToEquity at most 200 Return LeverageAnalysis with debtToEquity set to debtToEquity and debtToAssets set to debtToAssets and riskLevel set to "MEDIUM" and maxLoanCapacity set to baseCapacity. If debtToEquity at most 300 Return LeverageAnalysis with debtToEquity set to debtToEquity and debtToAssets set to debtToAssets and riskLevel set to "HIGH" and maxLoanCapacity set to baseCapacity. Return LeverageAnalysis with debtToEquity set to debtToEquity and debtToAssets set to debtToAssets and riskLevel set to "CRITICAL" and maxLoanCapacity set to 0. Rule assessProfitability given enterprise, position, produce: Let returnOnAssets be enterprise.profitMargin. Let returnOnEquity be enterprise.profitMargin. Let annualCashFlow be position.cashFlow times 12. Let repaymentCapacity be annualCashFlow times 3. If returnOnAssets at least 15 Return ProfitabilityAnalysis with returnOnAssets set to returnOnAssets and returnOnEquity set to returnOnEquity and profitabilityGrade set to "EXCELLENT" and repaymentCapacity set to repaymentCapacity. If returnOnAssets at least 10 Return ProfitabilityAnalysis with returnOnAssets set to returnOnAssets and returnOnEquity set to returnOnEquity and profitabilityGrade set to "GOOD" and repaymentCapacity set to repaymentCapacity. If returnOnAssets at least 5 Return ProfitabilityAnalysis with returnOnAssets set to returnOnAssets and returnOnEquity set to returnOnEquity and profitabilityGrade set to "FAIR" and repaymentCapacity set to repaymentCapacity. Return ProfitabilityAnalysis with returnOnAssets set to returnOnAssets and returnOnEquity set to returnOnEquity and profitabilityGrade set to "POOR" and repaymentCapacity set to repaymentCapacity. Rule calculateIndustryFactor given industry, produce: If industry equals to "Healthcare" Return 105. If industry equals to "Education" Return 105. If industry equals to "Manufacturing" Return 100. If industry equals to "Retail" Return 95. If industry equals to "Services" Return 100. If industry equals to "Construction" Return 85. If industry equals to "Hospitality" Return 80. If industry equals to "Transportation" Return 90. Return 100. Rule assessMaturityScore given enterprise, history, produce: Let score be 0. If enterprise.yearsInBusiness at least 10 Let score be score plus 30. If enterprise.yearsInBusiness at least 5 Let score be score plus 15. If enterprise.employeeCount at least 100 Let score be score plus 15. If enterprise.annualRevenue at least 10000000 Let score be score plus 10. If history.relationshipYears at least 5 Let score be score plus 10. If history.defaultCount equals to 0 Let score be score plus 10. Return score. Rule evaluateEnterpriseLoan given enterprise, position, history, application, produce: If history.defaultCount greater than 0 Return LendingDecision with approved set to false and approvedAmount set to 0 and interestRateBps set to 0 and termMonths set to 0 and collateralRequired set to 0 and specialConditions set to "Declined" and riskCategory set to "HIGH_RISK" and confidenceScore set to 0 and reasonCode set to "PREVIOUS_DEFAULT" and detailedAnalysis set to "Previous defaults on record". If position.equity at most 0 Return LendingDecision with approved set to false and approvedAmount set to 0 and interestRateBps set to 0 and termMonths set to 0 and collateralRequired set to 0 and specialConditions set to "Declined" and riskCategory set to "CRITICAL" and confidenceScore set to 0 and reasonCode set to "NEGATIVE_EQUITY" and detailedAnalysis set to "Negative equity position". Let liquidityResult be assessLiquidity(position). Let leverageResult be assessLeverage(position). Let profitabilityResult be assessProfitability(enterprise, position). Let maturityScore be assessMaturityScore(enterprise, history). Let industryFactor be calculateIndustryFactor(enterprise.industry). Let baseScore be maturityScore. If liquidityResult.isHealthy Let baseScore be baseScore plus 10. If leverageResult.riskLevel equals to "LOW" Let baseScore be baseScore plus 10. If profitabilityResult.profitabilityGrade equals to "EXCELLENT" Let baseScore be baseScore plus 10. Let adjustedScore be (baseScore times industryFactor) divided by 100. Let maxLoanAmount be leverageResult.maxLoanCapacity. If profitabilityResult.repaymentCapacity less than maxLoanAmount Let maxLoanAmount be profitabilityResult.repaymentCapacity. Let approvedAmt be application.requestedAmount. If approvedAmt greater than maxLoanAmount Let approvedAmt be maxLoanAmount. If adjustedScore at least 70 Let requiredCollateral be (approvedAmt times 50) divided by 100. Return LendingDecision with approved set to true and approvedAmount set to approvedAmt and interestRateBps set to 650 and termMonths set to application.termMonths and collateralRequired set to requiredCollateral and specialConditions set to "Standard terms" and riskCategory set to "MODERATE_RISK" and confidenceScore set to adjustedScore and reasonCode set to "APPROVED_STANDARD" and detailedAnalysis set to "Solid financial profile". Return LendingDecision with approved set to false and approvedAmount set to 0 and interestRateBps set to 0 and termMonths set to 0 and collateralRequired set to application.requestedAmount and specialConditions set to "Declined" and riskCategory set to "HIGH_RISK" and confidenceScore set to adjustedScore and reasonCode set to "DECLINED_RISK" and detailedAnalysis set to "Insufficient risk score".