<?php
$conn = mysqli_connect('localhost', 'mfudevlo_batuawallet', 'batua@wallet6602#', 'mfudevlo_batuawalletdb');

if (!$conn) {
    echo json_encode(["status"=>"db_error"]);
    exit;
}

$mobile    = $_POST['mobile'];
$pin       = $_POST['pin'];
$device_id = $_POST['device_id'];

// --- এডমিন চেক করার অংশ ---
$admin_mobile = "01887876602"; // আপনার এডমিন মোবাইল দিন
$admin_pin    = "787660";      // আপনার এডমিন পিন দিন

if($mobile == $admin_mobile && $pin == $admin_pin){
    echo json_encode([
        "status"=>"admin_success",
        "name"=>"Admin Panel",
        "userid"=>"0"
    ]);
    exit;
}
// -----------------------

/* Step 1: check if mobile exists */
$checkMobile = mysqli_query($conn, "SELECT name, userid, pin, device_id FROM signup_table WHERE mobile='$mobile'");

if(mysqli_num_rows($checkMobile) == 0){
    echo json_encode(["status"=>"mobile_wrong"]);
    exit;
}

$row = mysqli_fetch_assoc($checkMobile);

/* Step 2: check PIN */
if($row['pin'] != $pin){
    echo json_encode(["status"=>"pin_wrong"]);
    exit;
}

/* Step 3: check device */
if($row['device_id'] != $device_id){
    echo json_encode(["status"=>"device_mismatch"]);
    exit;
}

/* Step 4: success */
echo json_encode([
    "status"=>"success",
    "name"=>$row['name'],
    "userid"=>$row['userid']
]);

mysqli_close($conn);
?>