<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class School extends Model
{
    protected $fillable = [
        'name', 'code', 'email', 'phone', 'address', 'logo',
        'motto', 'county', 'sub_county', 'type', 'is_active', 'settings',
    ];

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

    public function users() { return $this->hasMany(User::class); }
    public function academicYears() { return $this->hasMany(AcademicYear::class); }
    public function classes() { return $this->hasMany(SchoolClass::class, 'school_id'); }
    public function subjects() { return $this->hasMany(Subject::class); }
    public function students() { return $this->hasMany(Student::class); }
    public function teachers() { return $this->hasMany(Teacher::class); }
    public function exams() { return $this->hasMany(Exam::class); }

    public function currentYear()
    {
        return $this->hasOne(AcademicYear::class)->where('is_current', true);
    }
}
