<?php

require_once BASE_PATH . '/app/models/Service.php';
require_once BASE_PATH . '/app/models/ServiceCategory.php';

class ServiceController
{
    private Service $services;
    private ServiceCategory $categories;

    public function __construct()
    {
        $this->services = new Service();
        $this->categories = new ServiceCategory();
    }

    public function index(): void
    {
        $search = trim((string) ($_GET['search'] ?? ''));
        $category = trim((string) ($_GET['category'] ?? ''));
        $services = $this->services->getPublic($search, $category);
        $categories = $this->categories->getActive();
        require BASE_PATH . '/app/views/services/index.php';
    }

    public function detail(): void
    {
        $service = $this->services->findActiveBySlug(trim((string) ($_GET['slug'] ?? '')));
        if (!$service) {
            http_response_code(404);
            require BASE_PATH . '/app/views/errors/404.php';
            return;
        }
        require BASE_PATH . '/app/views/services/detail.php';
    }
}
