<?php
header('Access-Control-Allow-Origin: *');
header(
    'Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS'
);
header(
    'Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'
);
header('Content-Type: application/json');

include '../../../../config/db.php';

// Service count
$serviceQuery = 'SELECT * FROM Services WHERE `status` <> -1';
$serviceResult = mysqli_query( $con, $serviceQuery );
$serviceCount = mysqli_num_rows($serviceResult);
// Order count
$orderQuery = 'SELECT * FROM Orders';
$orderResult = mysqli_query( $con, $orderQuery );
$orderCount = mysqli_num_rows($orderResult);
// Customers count
$customerQuery = 'SELECT * FROM Users';
$customerResult = mysqli_query( $con, $customerQuery );
$customerCount = mysqli_num_rows($customerResult);
// Messages count
$messageQuery = 'SELECT * FROM Messages';
$messageResult = mysqli_query( $con, $messageQuery );
$messageCount = mysqli_num_rows($messageResult);

$innerArray = array(
    'services' => $serviceCount,
    'orders' => $orderCount,
    'customers' => $customerCount,
    'messages' => $messageCount
);
$response = array(
    'status' => 'success',
    'data' => json_encode($innerArray)
);

// Return response as JSON
header( 'Content-Type: application/json' );
echo json_encode( $response );

?>