<?php

namespace App\Http\Controllers\api\v1\User;

use App\Http\Controllers\Controller;
use App\Service\User\ServiceItemService;
use App\Traits\JsonResponseTrait;
use Illuminate\Http\Request;

class ServiceItemController extends Controller
{
    use JsonResponseTrait;
    
    public function __construct(protected ServiceItemService $serviceItemService)
    {
    }

    /**
     * Get available service items for browsing
     */
    public function index(Request $request)
    {
        $filters = $request->only(['search', 'category_id', 'has_vendors', 'min_price', 'max_price', 'sort_by', 'sort_order', 'per_page', 'page']);
        return $this->serviceItemService->getAvailableServiceItems($filters);
    }

    /**
     * Get service item by ID with vendor options
     */
    public function show(string $service_item_id)
    {
        return $this->serviceItemService->getServiceItemById($service_item_id);
    }

    /**
     * Get vendors offering specific service item
     */
    public function vendors(Request $request, string $service_item_id)
    {
        $filters = $request->only(['search', 'min_price', 'max_price', 'sort_by', 'sort_order', 'per_page', 'page']);
        return $this->serviceItemService->getServiceItemVendors($service_item_id, $filters);
    }

    /**
     * Get service categories
     */
    public function categories(Request $request)
    {
        $filters = $request->only(['search', 'min_services', 'max_services', 'sort_by', 'sort_order', 'per_page', 'page']);
        return $this->serviceItemService->getServiceCategories($filters);
    }

    /**
     * Get service item features
     */
    public function features(string $service_item_id)
    {
        return $this->serviceItemService->getServiceItemFeatures($service_item_id);
    }
}
