<?php

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

$provider_id = ProviderAuth::id();

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

/*
SERVICES
*/

$query="

SELECT
psc.id,
c.name AS category,
sc.name AS subcategory

FROM provider_service_categories psc
JOIN categories c ON psc.category_id=c.id
JOIN sub_categories sc ON psc.sub_category_id=sc.id

WHERE psc.provider_id=:provider

";

$stmt=$conn->prepare($query);
$stmt->execute([':provider'=>$provider_id]);

$services=$stmt->fetchAll();


/*
AREAS
*/

$query="

SELECT
psa.id,
p.pincode,
p.area_name,
c.name AS city,
s.name AS state

FROM provider_service_areas psa

JOIN pincodes p ON psa.pincode_id=p.id
JOIN cities c ON p.city_id=c.id
JOIN states s ON c.state_id=s.id

WHERE psa.provider_id=:provider

";

$stmt=$conn->prepare($query);
$stmt->execute([':provider'=>$provider_id]);

$areas=$stmt->fetchAll();


Response::success([
"services"=>$services,
"areas"=>$areas
]);
