<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Response;
use App\Config\Database;

class HSNController extends Controller
{
    public function search(): void
    {
        $q = $_GET['q'] ?? '';
        if (empty($q))
            Response::success([]);

        $db = Database::getInstance();
        $stmt = $db->prepare("SELECT code, description, gst_rate FROM hsn_codes WHERE code LIKE ? OR description LIKE ? LIMIT 10");
        $stmt->execute(["%$q%", "%$q%"]);
        Response::success($stmt->fetchAll());
    }
}
