<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class CustomPage extends Model
{
    protected $fillable = ['page_group_id', 'title', 'slug', 'content', 'is_bottom_link', 'is_active', 'sort_order'];

    protected $casts = [
        'is_bottom_link' => 'boolean',
        'is_active' => 'boolean',
    ];

    // Auto-generate slug when creating a page
    protected static function boot()
    {
        parent::boot();
        static::creating(function ($page) {
            if (empty($page->slug)) {
                $page->slug = Str::slug($page->title);
            }
        });
    }

    public function group()
    {
        return $this->belongsTo(PageGroup::class, 'page_group_id');
    }
}