<?php

namespace App\Policies;

use App\Models\Post;
use App\Models\User;

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

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

    public function update(User $user, Post $post): bool
    {
        if ($user->can('content.posts.update-all')) {
            return true;
        }
        return $user->can('content.posts.update') && $post->user_id === $user->id;
    }

    public function delete(User $user, Post $post): bool
    {
        return $user->can('content.posts.delete');
    }
}
