<?php

namespace App\Modules\HR\Offboarding\Policies;

use App\Models\User;
use App\Modules\HR\Offboarding\Models\OffboardingCase;

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

    public function view(User $user, OffboardingCase $case): bool
    {
        return $this->tenant($user, $case) && $user->can('offboarding.view');
    }

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

    public function update(User $user, OffboardingCase $case): bool
    {
        return $this->tenant($user, $case) && $user->can('offboarding.update');
    }

    public function manage(User $user, OffboardingCase $case): bool
    {
        return $this->tenant($user, $case) && $user->can('offboarding.manage');
    }

    private function tenant(User $user, OffboardingCase $case): bool
    {
        return (int) $user->tenant_id === (int) $case->tenant_id;
    }
}
