<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class StudentClass extends Model
{
    use HasFactory;

    protected $table = 'student_classes';
    protected $fillable = [
        'student_id',
        'student_register_id',
        'teacher_class_id',
        'teacher_id',
        'class_id',
        'section',
        'subject_id',
    ];
    
    protected $casts = [
        'student_id' => 'integer',
        'student_register_id' => 'integer',
        'teacher_class_id' => 'integer',
        'teacher_id' => 'integer',
        'class_id' => 'integer',
        'subject_id' => 'integer',
    ];

    // Relationship with StudentRegister
    public function studentRegister()
    {
        return $this->belongsTo(StudentRegister::class, 'student_register_id');
    }

    public function teacherClass()
    {
        return $this->belongsTo(TeacherClass::class, 'teacher_class_id', 'id');
    }

    // Relationship with Class (if needed)
    public function classRelation()
    {
        return $this->belongsTo(Classes::class, 'class_id')->withTrashed();
    }

    public function section()
    {
        return $this->belongsTo(Section::class, 'section_id')->withTrashed();
    }

    public function subject()
    {
        return $this->belongsTo(Subject::class, 'subject_id')->withTrashed();
    }

    public function teacher()
    {
        return $this->belongsTo(Teacher::class, 'teacher_id');
    }

    public function student()
    {
        return $this->belongsTo(Student::class, 'student_id');
    }

    public function subjects()
    {
        return $this->hasMany(Subject::class, 'class_id'); // Use the correct foreign key
    }
}
