<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WebinarAcademySection extends Model
{
    protected $table = 'webinar_academy_sections';
    public $timestamps = true;
    protected $guarded = ['id'];
    
    protected $fillable = [
        'webinar_id',
        'title',
        'status',
        'order'
    ];

    public function webinar()
    {
        return $this->belongsTo('App\Models\Webinar', 'webinar_id', 'id');
    }

    public function boxes()
    {
        $relation = $this->hasMany('App\Models\WebinarAcademySectionBox', 'webinar_academy_section_id', 'id')->orderBy('order', 'asc');
        
        // Debug logging
        \Log::info('=== WebinarAcademySection Model: boxes relation called ===');
        \Log::info('Academy Section ID: ' . $this->id);
        \Log::info('Webinar ID: ' . $this->webinar_id);
        
        // Check database directly
        $dbBoxes = \DB::table('webinar_academy_section_boxes')
            ->where('webinar_academy_section_id', $this->id)
            ->orderBy('order', 'asc')
            ->get();
        
        \Log::info('Boxes in database: ' . $dbBoxes->count());
        foreach ($dbBoxes as $dbBox) {
            \Log::info('DB Box:', [
                'id' => $dbBox->id,
                'section_id' => $dbBox->webinar_academy_section_id,
                'title' => $dbBox->title,
                'order' => $dbBox->order,
            ]);
        }
        
        return $relation;
    }
}

