<?php

declare(strict_types=1);

namespace App\Models;

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

class CreatorMilestone extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'type',
        'occurred_at',
        'occurred_year',
        'related_artwork_id',
        'is_public',
        'priority',
        'payload_json',
        'computed_at',
    ];

    protected $casts = [
        'occurred_at' => 'datetime',
        'occurred_year' => 'integer',
        'related_artwork_id' => 'integer',
        'is_public' => 'boolean',
        'priority' => 'integer',
        'payload_json' => 'array',
        'computed_at' => 'datetime',
    ];

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

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