<?php

namespace App\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;

use App\Models\{Netmail,User};

class NetmailPolicy
{
	use HandlesAuthorization;

	/**
	 * This determines whether a logged-in user can view a netmail
	 *
	 * @param User $user
	 * @param Netmail $o
	 * @return bool
	 */
	public function view(User $user, Netmail $o): bool
	{
		$zones = $user->zc()->pluck('zone')
			//->merge($user->rc()->pluck('zone'))
			//->merge($user->nc()->pluck('zone'))
			//->merge($user->hub()->pluck('zone'))
			->merge($user->points()->pluck('zone'));

		// Site Admins can always view
		return (
			$user->isAdmin()
			|| ($zones->contains($o->fftn->zone))
			|| ($zones->contains($o->tftn->zone))
		);
	}
}