<?php
/**
 * POST /api/business/subscription_interest.php
 * Business-only. Body (JSON): { plan_interest, notes? }
 * Captures interest for when paid plans go live later - does not charge
 * anything or change subscription_status (that stays admin-controlled).
 */

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

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

$input = get_json_input();
$planInterest = trim($input['plan_interest'] ?? '');
$notes = trim($input['notes'] ?? '');

$validInterests = ['free_only', 'interested_paid', 'not_sure'];
if (!in_array($planInterest, $validInterests, true)) {
    send_error('plan_interest must be one of: ' . implode(', ', $validInterests), 422);
}

$pdo = Database::connect();
$stmt = $pdo->prepare('UPDATE business_profiles SET subscription_plan = ?, subscription_notes = ? WHERE user_id = ?');
$stmt->execute([$planInterest, $notes ?: null, $userId]);

send_json(true, 'Thanks - we\'ll keep this on file for when paid plans are introduced.');
