(*
   --------------------------------------------------------------------------
   title: Financial Transaction Validation
   description: Transaction validation with risk assessment
   order: 3
   --------------------------------------------------------------------------

   Real-world example: Financial Transaction Validation

   Use case: Validate financial transactions based on amount, account balance,
   and risk assessment.

   Practical implications:
   - Ensures all transaction scenarios are covered
   - Identifies edge cases in fraud detection logic
   - Provides test cases for transaction processing
   - Helps verify compliance with financial regulations
*)

type transaction_status = Approved | ManualReview | Rejected

(* Transaction risk score based on amount *)
let risk_score amount =
  if amount <= 100 then
    "low"
  else if amount <= 1000 then
    "medium"
  else
    "high"

(* Validate a transaction *)
let validate_transaction amount balance is_verified_account =
  if amount <= 0 then
    Rejected
  else if amount > balance then
    Rejected
  else if amount > 10000 then
    (* Large transactions always need review *)
    ManualReview
  else if amount > 5000 && not is_verified_account then
    (* Unverified accounts need review for medium-large amounts *)
    ManualReview
  else if is_verified_account then
    Approved
  else if amount <= 1000 then
    (* Small transactions from unverified accounts are OK *)
    Approved
  else
    ManualReview
[@@decomp top ~basis:[[%id risk_score]] ~prune:true ()]

(* Variation: With contextual simplification *)
let validate_transaction_valid amount balance is_verified_account =
  if amount > 10000 then
    ManualReview
  else if amount > 5000 && not is_verified_account then
    ManualReview
  else if is_verified_account then
    Approved
  else if amount <= 1000 then
    Approved
  else
    ManualReview
[@@decomp top ~ctx_simp:true ()]
