<?php

namespace App\Domains\Analytics\Models;

use App\Domains\Link\Models\Link;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Click extends Model
{
    public $timestamps = false;

    protected $guarded = [];

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

    // Prevent updates — clicks are append-only
    public function save(array $options = []): bool
    {
        if ($this->exists) {
            throw new \LogicException('Click records are append-only.');
        }

        return parent::save($options);
    }

    /** @return BelongsTo<Link, $this> */
    public function link(): BelongsTo
    {
        return $this->belongsTo(Link::class);
    }
}
