<?php

namespace App\Policies;

use App\Models\User;
use App\Models\Branch;

class BranchPolicy
{
    public function before(User $user, $ability)
    {
        if ($user->isAdmin()) return true;
    }

    public function viewAny(User $user)
    {
        return $user->isLeasing() || $user->isAdmin();
    }

    public function view(User $user, Branch $branch)
    {
        return $user->isLeasing() && $user->leasing_profile->id === $branch->leasing_id;
    }

    public function create(User $user)
    {
        return $user->isLeasing();
    }

    public function update(User $user, Branch $branch)
    {
        return $user->isLeasing() && $user->leasing_profile->id === $branch->leasing_id;
    }

    public function delete(User $user, Branch $branch)
    {
        return $user->isLeasing() && $user->leasing_profile->id === $branch->leasing_id;
    }
}
