<?php

declare(strict_types=1);

namespace App\Models;

use App\Models\Concerns\HasDberpAuditTrail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class DberpUserPermissionGrant extends Model
{
    use HasDberpAuditTrail;

    protected $table = 'dberp_user_permission_grants';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'user_id',
        'permission_code',
        'granted_by',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'user_id' => 'integer',
            'granted_by' => 'integer',
        ];
    }

    public function getDberpAuditActionPrefix(): string
    {
        return 'dberp.user_permission_grant';
    }

    /**
     * @return list<string>
     */
    public function getDberpAuditFields(): array
    {
        return $this->getFillable();
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function grantedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'granted_by');
    }
}