<?php

namespace App\Modules\HR\Assets\Policies;

use App\Models\User;
use App\Modules\HR\Assets\Models\Asset;

class AssetPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->can('assets.view');
    }

    public function view(User $user, Asset $asset): bool
    {
        return $this->sameTenant($user, $asset) && $user->can('assets.view');
    }

    public function create(User $user): bool
    {
        return $user->can('assets.create');
    }

    public function update(User $user, Asset $asset): bool
    {
        return $this->sameTenant($user, $asset) && $user->can('assets.update');
    }

    public function manage(User $user, Asset $asset): bool
    {
        return $this->sameTenant($user, $asset) && $user->can('assets.manage');
    }

    private function sameTenant(User $user, Asset $asset): bool
    {
        return (int) $user->tenant_id === (int) $asset->tenant_id;
    }
}
