<?php

namespace App\Models;

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

/**
 * App\Models\ArtworkMetricSnapshotHourly
 *
 * Stores hourly totals for artwork metrics. Deltas are computed by
 * subtracting the previous hour's snapshot from the current one.
 *
 * @property int $id
 * @property int $artwork_id
 * @property \Illuminate\Support\Carbon $bucket_hour
 * @property int $views_count
 * @property int $downloads_count
 * @property int $favourites_count
 * @property int $comments_count
 * @property int $shares_count
 * @property \Illuminate\Support\Carbon $created_at
 */
class ArtworkMetricSnapshotHourly extends Model
{
    protected $table = 'artwork_metric_snapshots_hourly';

    public $timestamps = false;

    protected $fillable = [
        'artwork_id',
        'bucket_hour',
        'views_count',
        'downloads_count',
        'favourites_count',
        'comments_count',
        'shares_count',
    ];

    protected $casts = [
        'bucket_hour'      => 'datetime',
        'views_count'      => 'integer',
        'downloads_count'  => 'integer',
        'favourites_count' => 'integer',
        'comments_count'   => 'integer',
        'shares_count'     => 'integer',
    ];

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