<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Subject;
use App\Models\User; // Pastikan Model User di-import

class SemesterProgram extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    // Casts untuk mengubah kolom JSON jadi Array otomatis
    protected $casts = [
        'monthly_distribution' => 'array',
        'bulan_minggu' => 'array', // Tambahkan ini jika Anda menggunakan kolom 'bulan_minggu' di database
    ];

    // --- RELASI ---

    // Relasi standar ke User
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // Relasi 'guru' (Alias untuk user, agar with('guru') di controller jalan)
    public function guru()
    {
        // Mengarah ke model User, menggunakan foreign key 'user_id'
        return $this->belongsTo(User::class, 'user_id');
    }

    // Relasi standar ke Subject
    public function subject()
    {
        return $this->belongsTo(Subject::class);
    }

    // Relasi 'mapel' (Alias untuk subject, agar with('mapel') di controller jalan)
    public function mapel()
    {
        return $this->belongsTo(Subject::class, 'subject_id');
    }
}