<?php

namespace App\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class OperationLog extends BaseModel
{
    protected $table = 'admin_operation_logs';

    public const CREATED_AT = 'create_time';

    public const UPDATED_AT = 'update_time';

    protected $dateFormat = 'Y-m-d H:i:s';

    protected $fillable = [
        'user_id',
        'module',
        'action',
        'method',
        'path',
        'params',
        'ip',
        'user_agent',
        'status',
        'error_message',
    ];

    protected $casts = [
        'params' => 'array',
        'create_time' => 'datetime:Y-m-d H:i:s',
        'update_time' => 'datetime:Y-m-d H:i:s',
    ];

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