<?php

namespace App\Policies;

use App\Models\FixedAsset;
use App\Models\User;
use App\Services\BranchAccessService;
use App\Support\Authorization\PermissionName;

class FixedAssetPolicy
{
    public function __construct(private BranchAccessService $branchAccess) {}

    public function view(User $user, FixedAsset $fixedAsset): bool
    {
        return $user->can(PermissionName::FIXED_ASSETS_VIEW->value)
            && $this->branchAccess->canAccessBranch($user, (int) $fixedAsset->branch_id);
    }

    public function manage(User $user, FixedAsset $fixedAsset): bool
    {
        return $user->can(PermissionName::FIXED_ASSETS_MANAGE->value)
            && $this->branchAccess->canAccessBranch($user, (int) $fixedAsset->branch_id);
    }

    public function depreciate(User $user, FixedAsset $fixedAsset): bool
    {
        return $user->can(PermissionName::FIXED_ASSETS_DEPRECIATE->value)
            && $this->branchAccess->canAccessBranch($user, (int) $fixedAsset->branch_id);
    }

    public function maintenance(User $user, FixedAsset $fixedAsset): bool
    {
        return $user->can(PermissionName::FIXED_ASSETS_MAINTENANCE->value)
            && $this->branchAccess->canAccessBranch($user, (int) $fixedAsset->branch_id);
    }
}
