<?php

namespace App\Models\SecurityManagement;

use App\Models\Traits\Bootables\Auditable;
use App\Models\Traits\HasDates;
use App\Models\UserManagement\Admin;
use Axn\EloquentAuthorable\AuthorableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Permission\Models\Role as SpatieRole;

class Role extends SpatieRole{
    use HasFactory,SoftDeletes,HasDates, Auditable, AuthorableTrait;

    protected $table = "security_mgt__roles";

    protected $hidden = ['pivot'];
    public $guard_name = "admin";

    protected $guarded = ['id'];
  //  const SLUG_ATTRIBUTS = ["id",'name'];

   // protected $dispatchesEvents = [];

    const SUPER_ADMIN = "Super-Admin";
    const CUSTOMER = "Customer";

    protected $appends = [
       "permissions_ids"
    ];

   // protected  $guard_name = 'resources';
    public function getRouteKeyName(){
        return "id";
    }

//    protected static function booted(){
//
//       static::addGlobalScope(new RoleGlobalScope);
//    }

    public function getPermissionsIdsAttribute(){
        return $this->permissions->pluck('id')->toArray();
    }


    public function createdBy(){
        return $this->belongsTo(Admin::class,"created_by");
    }

}
