
def calculate_interest_yield(amount, rate, tenor_days, basis, tax_percent):
    """
    Standardized interest calculation for the platform.
    """
    try:
        # Convert inputs to floats to ensure math works
        amt = float(amount)
        r = float(rate) / 100
        days = int(tenor_days)
        # Use 365 as safety fallback if basis is missing or 0
        b = float(basis) if basis and float(basis) > 0 else 365.0
        tax_r = float(tax_percent) / 100

        # Math Logic
        gross = (amt * r * days) / b
        tax_amount = gross * tax_r
        net = gross - tax_amount

        return round(gross, 2), round(tax_amount, 2), round(net, 2)
    except Exception as e:
        print(f"Calculation Error: {e}")
        return 0.0, 0.0, 0.0

def calc_interest(amount, rate, tenor_days, basis_text, tax_percent):
    
    try:
        amt = float(amount)
        r = float(rate) / 100
        days = int(tenor_days)
        tax_r = float(tax_percent) / 100

        # Independent basis logic
        if '360' in basis_text:
            b = 360.0
        else:
            # Assumes 365 for 'Act/365' or 'Act/Act'
            b = 365.0 

        # Independent math logic
        gross = (amt * r * days) / b
        tax_amount = gross * tax_r
        net = gross - tax_amount

        return round(gross, 2), round(tax_amount, 2), round(net, 2)

    except Exception as e:
        print(f"Independent Calculation Error: {e}")
        return 0.0, 0.0, 0.0