<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Permission extends Model
{
    protected $fillable = [
        'role_id',
        'name',
        'display_name',
        'description',
    ];

    public function role(): BelongsTo
    {
        return $this->belongsTo(Role::class);
    }

    public static function createDefaultPermissions()
    {
        $permissions = [
            ['name' => 'view-dashboard', 'display_name' => 'View Dashboard'],
            ['name' => 'manage-users', 'display_name' => 'Manage Users'],
            ['name' => 'manage-products', 'display_name' => 'Manage Products'],
            ['name' => 'manage-orders', 'display_name' => 'Manage Orders'],
            ['name' => 'manage-withdrawals', 'display_name' => 'Manage Withdrawals'],
            ['name' => 'view-reports', 'display_name' => 'View Reports'],
            ['name' => 'manage-settings', 'display_name' => 'Manage Settings'],
        ];

        foreach ($permissions as $permission) {
            self::firstOrCreate($permission);
        }
    }
}
