<?php

namespace App\Models\Webprofile;

use App\Http\Traits\UuidTrait;
use App\Models\Webprofile\De\Menu as DeMenu;
use App\Models\Webprofile\En\Menu as EnMenu;
use App\Models\Webprofile\Sa\Menu as SaMenu;
use App\Models\Webprofile\Zh\Menu as ZhMenu;
use Illuminate\Database\Eloquent\Model;

class Menu extends Model
{
    use UuidTrait;

    public $incrementing = false;
    protected $table = 'swp_menus';

    protected $fillable = [
        'id', 'name', 'url', 'mode', 'status', 'parent', 'urutan', 'parentlevel', 'level', 'userid_created', 'userid_updated',
    ];

    public static $rules = [
        // 'name' => 'required',
    ];

    public static $errormessage = [
        'required' => 'Form Input Ini Tidak Boleh Kosong / Harus Diisi',
    ];

    public function rEn()
    {
        return $this->hasOne(EnMenu::class, 'menu_id', 'id');
    }

    public function rDe()
    {
        return $this->hasOne(DeMenu::class, 'menu_id', 'id');
    }

    public function rSa()
    {
        return $this->hasOne(SaMenu::class, 'menu_id', 'id');
    }

    public function rZh()
    {
        return $this->hasOne(ZhMenu::class, 'menu_id', 'id');
    }

    public function rChild()
    {
        return $this->hasMany(Menu::class, 'parent', 'id')->orderBy('urutan', 'asc')->with(['rChild', 'rEn']);
    }
}
