<?php

namespace App\Repositories\Core\App;

use App\Models\Core\App\ApplicationModule;

class ApplicationModules
{
    public static function select_all()
    {
        return ApplicationModule::all()->toArray();
    }

    public static function getOptions()
    {
        return ApplicationModule::pluck('name', 'id')->toArray();
    }

    public static function edit($id)
    {
        return self::get($id)->toArray();
    }

    public static function store($data)
    {
        $id = isset($data['id']) ? $data['id'] : false;

        return $id ? self::update($data, $id) : self::create($data);
    }

    public static function create($data)
    {
        return ApplicationModule::create($data);
    }

    public static function update($data, $id = false)
    {
        $id = $id ? $id : $data['id'];

        return self::get($id)->update($data);
    }

    public static function destroy($id)
    {
        return ApplicationModule::destroy($id);
    }

    public static function getName($id)
    {
        return self::get($id)->name;
    }

    public static function get($id)
    {
        return ApplicationModule::findOrFail($id);
    }
}
