<?php

declare(strict_types=1);

namespace Plugins\Neatstudio\LinkTracker\Models;

use Illuminate\Database\Eloquent\Model;

class Redirect extends Model
{
    protected $fillable = [
        'hash', 'target_url', 'clicks', 'status', 'last_clicked_at',
    ];

    protected $casts = [
        'last_clicked_at' => 'datetime',
    ];

    public function isActive(): bool
    {
        return $this->status === 'active';
    }

    public function hit(): void
    {
        $this->increment('clicks');
        $this->update(['last_clicked_at' => now()]);
    }
}
