<?php

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

use App\Http\Controllers\Controller;
use App\Service\Vendor\ServiceItemService;
use App\Http\Requests\Vendor\CreateVendorServiceRequest;
use App\Http\Requests\Vendor\UpdateVendorServiceRequest;
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 vendor customization
     */
    public function index(Request $request)
    {
        $authUser = $request->user();
        $filters = $request->only(['search', 'category_id', 'vendor_services_only', 'sort_by', 'sort_order', 'per_page', 'page']);
        return $this->serviceItemService->getAvailableServiceItems($authUser, $filters);
    }

    /**
     * Get service item by ID
     */
    public function show(Request $request, string $service_item_id)
    {
        $authUser = $request->user();
        return $this->serviceItemService->getServiceItemById($authUser, $service_item_id);
    }

    /**
     * Create vendor service
     */
    public function store(CreateVendorServiceRequest $request)
    {
        $authUser = $request->user();
        $input = $request->validated();
        return $this->serviceItemService->createVendorService($authUser, $input);
    }

    /**
     * Update vendor service
     */
    public function update(UpdateVendorServiceRequest $request, string $vendor_service_id)
    {
        $authUser = $request->user();
        $input = $request->validated();
        return $this->serviceItemService->updateVendorService($authUser, $vendor_service_id, $input);
    }

    /**
     * Delete vendor service
     */
    public function destroy(Request $request, string $vendor_service_id)
    {
        $authUser = $request->user();
        return $this->serviceItemService->deleteVendorService($authUser, $vendor_service_id);
    }

    /**
     * Toggle vendor service status
     */
    public function toggleStatus(Request $request, string $vendor_service_id)
    {
        $authUser = $request->user();
        return $this->serviceItemService->toggleVendorServiceStatus($authUser, $vendor_service_id);
    }

    /**
     * Get vendor's services
     */
    public function myServices(Request $request)
    {
        $authUser = $request->user();
        $filters = $request->only(['search', 'status', 'service_item_id', 'sort_by', 'sort_order', 'per_page', 'page']);
        return $this->serviceItemService->getVendorServices($authUser, $filters);
    }
}
