<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class AuditLog extends Model
{
    protected $fillable = ['user_id', 'action', 'details', 'ip'];

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

    public static function record(string $action, string $details = '', $userId = null): void
    {
        static::create([
            'user_id' => $userId ?? auth()->id(),
            'action'  => $action,
            'details' => $details,
            'ip'      => request()->ip(),
        ]);
    }
}
