<?php

namespace App\Policies;

use App\Models\Communication\Recording;
use App\Models\User\User;

class RecordingPolicy
{
    public function view(User $user, Recording $recording): bool
    {
        if ($user->can('communications.recordings.view.all')) {
            return true;
        }

        $call = $recording->call;

        return $call
            && ($call->assigned_agent_id === $user->id || $call->answered_by_agent_id === $user->id);
    }
}
