<?php


require_once '../../core/api_bootstrap.php';
require_once '../../core/provider_auth.php';

$provider_id = ProviderAuth::id();

$data = Request::get();

try {

    Validator::required($data, ['provider_id']);

    $db = new Database();
    $conn = $db->connect();

    $stmt = $conn->prepare("

SELECT

usage_date,
leads_received

FROM provider_lead_usage

WHERE provider_id=:provider

ORDER BY usage_date DESC

LIMIT 30

");

    $stmt->execute([
        ':provider' => $data['provider_id']
    ]);

    $data = $stmt->fetchAll();

    Response::success($data);

} catch (Exception $e) {

    Logger::log("system.log", $e->getMessage());

    Response::error("Server error", 500);

}