<?php

namespace App\Policies;

use App\Models\Organization;
use App\Models\User;
use App\Models\Video;

class VideoPolicy extends BasePolicy
{
    public function viewAny(User $user, ?Organization $organization = null): bool
    {
        return $this->belongsToOrganization($user, $organization);
    }

    public function update(User $user, Video $video, ?Organization $organization = null): bool
    {
        if (!$this->belongsToOrganization($user, $organization)) {
            return false;
        }

        $booking = $video->booking;

        if (!$booking) {
            return false;
        }

        return $this->resourceBelongsToOrganization($booking, $organization, $user);
    }
}
