<?php

namespace App\Repositories\Eloquent;

use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Models\Role;

class RoleRepository extends BaseRepository
{
    protected function resolveModel(): Model
    {
        return new Role();
    }

    public function findByName(string $name): ?Role
    {
        return $this->executeWithLogging(__FUNCTION__, function () use ($name) {
            return $this->model->where('name', $name)->where('guard_name', 'sanctum')->first();
        });
    }

    public function getAllWithPermissions()
    {
        return $this->executeWithLogging(__FUNCTION__, function () {
            return $this->model->where('guard_name', 'sanctum')->with('permissions')->get();
        });
    }
}
