<?php

namespace App\Models;

use App\Core\Traits\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ApiLog extends Model
{
    use HasUuid;

    protected $table = 'api_logs';

    protected $fillable = [
        'user_id',
        'method',
        'path',
        'controller_action',
        'request_body',
        'request_headers',
        'response_status',
        'response_body',
        'duration_ms',
        'ip_address',
        'user_agent',
        'device',
    ];

    protected function casts(): array
    {
        return [
            'request_body' => 'array',
            'request_headers' => 'array',
            'response_body' => 'array',
            'duration_ms' => 'float',
        ];
    }

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