<?php

namespace App\Policies;

use App\Models\PlayerGameProfile;
use App\Models\User;

class PlayerGameProfilePolicy
{
    public function viewAny(User $user): bool
    {
        return $user->playerProfile !== null;
    }

    public function create(User $user): bool
    {
        return $user->playerProfile !== null;
    }

    public function view(User $user, PlayerGameProfile $profile): bool
    {
        return $user->isAdmin()
            || $profile->playerProfile?->user_id === $user->id;
    }

    public function update(User $user, PlayerGameProfile $profile): bool
    {
        return $profile->playerProfile?->user_id === $user->id;
    }

    public function delete(User $user, PlayerGameProfile $profile): bool
    {
        return $profile->playerProfile?->user_id === $user->id;
    }
}
