<?php

namespace Modules\ClinicSite\Entities;

use Illuminate\Database\Eloquent\Model;

class CsPage extends Model
{
    protected $table = 'cs_pages';
    protected $guarded = ['id'];

    protected $casts = [
        'is_home'     => 'boolean',
        'show_in_nav' => 'boolean',
        'blocks'      => 'array',
    ];

    public function site()
    {
        return $this->belongsTo(CsSite::class, 'site_id');
    }

    /** Normalised, ordered list of blocks ready for rendering. */
    public function orderedBlocks(): array
    {
        $blocks = $this->blocks ?? [];
        return is_array($blocks) ? array_values($blocks) : [];
    }
}
