<?php

namespace App\Models;

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

class AccessLog extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'server_resource_id',
        'bastion_account_id',
        'protocol',
        'action',
        'requested_at',
        'metadata',
    ];

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

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

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

    protected function casts(): array
    {
        return [
            'requested_at' => 'datetime',
            'metadata' => 'array',
        ];
    }
}
