<?php

namespace App\Models;

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

class ApiKey extends Model
{
    use HasFactory;

    /**
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'key_hash',
        'is_active',
        'last_used_at',
        'created_by',
    ];

    /**
     * @var array<string, string>
     */
    protected $casts = [
        'is_active' => 'boolean',
        'last_used_at' => 'datetime',
    ];

    public function ips(): HasMany
    {
        return $this->hasMany(ApiKeyIp::class);
    }

    public function logs(): HasMany
    {
        return $this->hasMany(ApiLog::class);
    }
}
