<?php

namespace App\Policies;

use App\Models\Project;
use App\Models\User;

class ProjectPolicy
{
    public function viewAny(User $user): bool
    {
        return true; // Everyone can see projects for now, role middleware handles access.
    }

    public function view(User $user, Project $project): bool
    {
        return $user->hasRole('super_admin') || 
               $user->hasRole('hr') || 
               $project->owner_id === $user->id ||
               $project->members->contains($user->id);
    }

    public function create(User $user): bool
    {
        return $user->hasRole('super_admin') || $user->hasRole('hr') || $user->hasRole('project_manager');
    }

    public function update(User $user, Project $project): bool
    {
        return $user->hasRole('super_admin') || $project->owner_id === $user->id;
    }

    public function delete(User $user, Project $project): bool
    {
        return $user->hasRole('super_admin');
    }
}
