<?php

namespace App\Services\SM;

use App\Models\SM\Permission;
use App\Traits\DataTable;
use Exception;

class PermissionService
{
    /**
     * Create a new class instance.
     */
    use DataTable;
    public function __construct(private Permission $model)
    {
        //
    }

    public function dataTable()
    {
        return $this->generate($this->model->query());
    }

    public function create($data)
    {
        return $this->model->create($data);
    }

    public function update($id, $data)
    {
        $permission = $this->model->findOr($id, fn () => throw new Exception("Permission not found"));
        $permission->update($data);
        return $permission;
    }

    public function detail($id)
    {
        return $this->model->findOr($id, fn () => throw new Exception("Permission not found"));
    }
}
