import type { CalcuttaCompetitionProps, CalcuttaEscrowProps } from '@bettoredge/types'; export const validateBidAmount = ( amount: number, current_bid: number, min_bid: number, bid_increment: number, auction_type: string, escrow?: CalcuttaEscrowProps, existing_bid_amount?: number ): string[] => { const errors: string[] = []; if (isNaN(amount) || amount <= 0) { errors.push('Please enter a valid bid amount'); return errors; } if (amount < min_bid) { errors.push(`Minimum bid is $${min_bid.toFixed(2)}`); } if (amount <= current_bid) { errors.push(`Bid must exceed current bid of $${current_bid.toFixed(2)}`); } if (auction_type === 'live' && amount < current_bid + bid_increment) { errors.push(`Minimum bid is $${(current_bid + bid_increment).toFixed(2)}`); } if (escrow) { const available = Number(escrow.escrow_balance) + (existing_bid_amount || 0); if (amount > available) { errors.push(`Insufficient escrow balance. Available: $${available.toFixed(2)}`); } } return errors; }; export const validateEscrowDeposit = (amount: number, max_escrow?: number, net_deposited?: number): string[] => { const errors: string[] = []; if (isNaN(amount) || amount <= 0) { errors.push('Please enter a valid amount'); } if (max_escrow != null && max_escrow > 0 && net_deposited != null) { const remaining = max_escrow - net_deposited; if (amount > remaining) { errors.push(`Budget cap is $${max_escrow.toFixed(2)}. You can deposit up to $${Math.max(0, remaining).toFixed(2)} more.`); } } return errors; }; export const validateEscrowWithdraw = (amount: number, available: number): string[] => { const errors: string[] = []; if (isNaN(amount) || amount <= 0) { errors.push('Please enter a valid amount'); } if (amount > available) { errors.push(`Maximum withdrawal is $${available.toFixed(2)}`); } return errors; };