<?php

namespace App\Models\Site;

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

class AgencySiteSection extends Model
{
    protected $fillable = [
        'page_id', 'section_type', 'sort_order', 'is_active', 'settings', 'data',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'settings' => 'array',
        'data' => 'array',
    ];

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

    public function setting(string $key, $default = null)
    {
        return data_get($this->settings, $key, $default);
    }

    public function content(string $key, $default = null)
    {
        return data_get($this->data, $key, $default);
    }
}
