<?php
header("Content-Type: application/json");
require_once "../config.php";

$borrower_type = $_GET['borrower_type'] ?? '';

try {
    $stmt = $dbh->prepare("SELECT * FROM borrow_rules WHERE borrower_type = :borrower_type LIMIT 1");
    $stmt->bindParam(':borrower_type', $borrower_type, PDO::PARAM_STR);
    $stmt->execute();
    $rule = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($rule) {
        echo json_encode([
            'status' => 'success',
            'data' => $rule
        ]);
    } else {
        echo json_encode([
            'status' => 'error',
            'message' => 'No borrow rule found'
        ]);
    }
} catch (PDOException $e) {
    echo json_encode([
        'status' => 'error',
        'message' => $e->getMessage()
    ]);
}
