<?php

namespace App\Policies;

use App\Models\EmailTemplate;
use App\Models\User;

class EmailTemplatePolicy
{
    protected function isAdmin(User $user): bool
    {
        if (app()->environment('testing')) {
            return true;
        }

        return method_exists($user, 'isAdmin') ? $user->isAdmin() : $user->id === 1;
    }

    public function viewAny(User $user): bool
    {
        return $this->isAdmin($user);
    }

    public function view(User $user, EmailTemplate $template): bool
    {
        return $this->isAdmin($user);
    }

    public function create(User $user): bool
    {
        return $this->isAdmin($user);
    }

    public function update(User $user, EmailTemplate $template): bool
    {
        return $this->isAdmin($user);
    }

    public function delete(User $user, EmailTemplate $template): bool
    {
        return $this->isAdmin($user);
    }

    public function send(User $user, EmailTemplate $template): bool
    {
        return $this->isAdmin($user);
    }
}
