<?php
// app/Traits/HasPackageAccess.php

namespace App\Traits;

use App\Services\PackageService;

trait HasPackageAccess
{
    /**
     * Check if current hotel has access to a module
     */
    protected function canAccess(string $moduleKey): bool
    {
        $hotel = auth()->user()->hotel;
        $packageService = app(PackageService::class);
        
        return $packageService->hasModuleAccess($hotel, $moduleKey);
    }
    
    /**
     * Get available modules for current hotel
     */
    protected function getAvailableModules(): array
    {
        $hotel = auth()->user()->hotel;
        $packageService = app(PackageService::class);
        
        return $packageService->getAvailableModules($hotel);
    }
    
    /**
     * Authorize module access or abort
     */
    protected function authorizeModule(string $moduleKey): void
    {
        if (!$this->canAccess($moduleKey)) {
            abort(403, 'This feature requires an upgraded package.');
        }
    }
}