<?php

namespace App\Models;

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

class PageContent extends Model
{
    protected $table = 'page_content';

    protected $fillable = [
        'section',
        'title_en',
        'title_km',
        'description_en',
        'description_km',
        'image',
        'created_by',
        'updated_by',
    ];

    /**
     * Get the user who created this page content
     */
    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**
     * Get the user who last updated this page content
     */
    public function updatedByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    /**
     * Get available sections
     */
    public static function getAvailableSections(): array
    {
        return ['home','home_promise', 'about', 'contact','terms', 'privacy'];
    }

    /**
     * Scope to filter by section
     */
    public function scopeBySection($query, $section)
    {
        return $query->where('section', $section);
    }
}
