<?php

namespace App\Modules\Admin\Tenancy\Repositories;

use App\Modules\Admin\Tenancy\Models\Module;
use Illuminate\Database\Eloquent\Collection;

class ModuleRepository
{
    public function all(): Collection
    {
        return Module::query()->orderBy('name')->get();
    }

    public function allActiveOrdered(): Collection
    {
        return Module::query()->active()->orderBy('name')->get();
    }

    /**
     * @return array<int, string>
     */
    public function activeForSelect(): array
    {
        return Module::query()
            ->active()
            ->orderBy('name')
            ->pluck('name', 'id')
            ->all();
    }

    public function create(array $data): Module
    {
        return Module::query()->create($data);
    }

    public function update(Module $module, array $data): Module
    {
        $module->update($data);

        return $module->fresh();
    }

    public function delete(Module $module): void
    {
        $module->delete();
    }
}
