<?php

namespace App\Models;

use App\Enums\PromptLandingPageVersionKind;
use Database\Factories\PromptLandingPageVersionFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

#[Fillable([
    'prompt_landing_page_id', 'version', 'kind', 'html', 'css', 'js', 'created_by', 'created_at',
])]
class PromptLandingPageVersion extends Model
{
    /** @use HasFactory<PromptLandingPageVersionFactory> */
    use HasFactory;

    public const UPDATED_AT = null;

    /**
     * @var array<string, mixed>
     */
    protected $attributes = [
        'kind' => 'published',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'kind' => PromptLandingPageVersionKind::class,
            'created_at' => 'datetime',
        ];
    }

    public function page(): BelongsTo
    {
        return $this->belongsTo(PromptLandingPage::class, 'prompt_landing_page_id');
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
