# weighted_mcc/binary.py
import numpy as np
from numpy.typing import NDArray

def weighted_mcc(
    y_true: NDArray[np.int_],
    y_pred: NDArray[np.int_],
    sample_weights: NDArray[np.float64]
) -> float:
    """
    Calculates Weighted MCC for binary classification.
    """
    t = np.asarray(y_true)
    c = np.asarray(y_pred)
    w = np.asarray(sample_weights)
    
    # Calculate weighted confusion matrix elements
    # TP = <t, c>_S
    tp = np.dot(w, t * c)
    
    # TN = <1-t, 1-c>_S
    tn = np.dot(w, (1 - t) * (1 - c))
    
    # FP = <1-t, c>_S
    fp = np.dot(w, (1 - t) * c)
    
    # FN = <t, 1-c>_S
    fn = np.dot(w, t * (1 - c))
    
    numerator = (tp * tn) - (fp * fn)
    denominator = np.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))
    
    if denominator == 0:
        return 0.0
        
    return float(numerator / denominator)