<?php

namespace App\Services\Admin;

use App\Models\Role;
use App\Services\BaseService;
use Illuminate\Support\Facades\Auth;
use Yajra\Datatables\Datatables;

class RoleService extends BaseService
{
    public function rolesList()
    {
        $usersList = Role::query();
        $datatable = Datatables::of($usersList);
        return collect($datatable->make(true)->getData());
    }

    public function getRoleDetail($id)
    {
        return Role::findOrFail($id);
    }

    public function createRole(array $data)
    {
        $attr = new Role();
        $attr->title = $data['title'] ?? null;
        $attr->added_by = Auth::id();
        $attr->save();
    }

    public function updateRole($data, $id)
    {
        $attr = Role::findOrFail($id);
        $attr->title = $data['title'] ?? null;
        $attr->updated_by = Auth::id();
        $attr->save();
    }
}
