<?php
/**
 * GET /api/business/profile.php
 * Business-only. Returns the caller's business profile + account email/phone.
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';
require_once __DIR__ . '/../includes/auth.php';

$userId = require_login();
require_role(['business']);

$pdo = Database::connect();
$stmt = $pdo->prepare('
    SELECT u.email, u.phone, bp.business_name, bp.category, bp.logo_path, bp.contact_person, bp.address, bp.city, bp.country, bp.latitude, bp.longitude
    FROM users u
    JOIN business_profiles bp ON bp.user_id = u.id
    WHERE u.id = ?
');
$stmt->execute([$userId]);
$profile = $stmt->fetch();

if (!$profile) {
    send_error('Business profile not found.', 404);
}

$profile['logo_url'] = $profile['logo_path'] ? UPLOAD_URL . $profile['logo_path'] : null;
unset($profile['logo_path']);

send_json(true, 'OK', ['profile' => $profile]);
