<?php

declare(strict_types=1);

namespace App\Models;

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

/**
 * Recommendation event log entry.
 *
 * @property int              $id
 * @property int|null         $user_id
 * @property string|null      $session_id
 * @property string           $event_type   view|favourite|download
 * @property int              $artwork_id
 * @property \Carbon\Carbon   $created_at
 *
 * @property-read User|null   $user
 * @property-read Artwork     $artwork
 */
final class RecEvent extends Model
{
    protected $table = 'rec_events';

    public $timestamps = false;

    protected $fillable = [
        'user_id',
        'session_id',
        'event_type',
        'artwork_id',
        'created_at',
    ];

    protected $casts = [
        'user_id'    => 'integer',
        'artwork_id' => 'integer',
        'created_at' => 'datetime',
    ];

    // ── Relations ──────────────────────────────────────────────────────────

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

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