<?php

namespace App\Models;

use App\Models\BaseModel;

class SchoolClass extends BaseModel
{
    protected $table = 'classes';

    // CI: useTimestamps = false
    public $timestamps = false;

    protected $fillable = [
        'class_name',
        'schedule',
        'capacity',
        'semester',
        'school_year',
    ];

    protected $casts = [
        'capacity' => 'integer',
    ];

    /* =========================
     * CI method equivalents
     * ========================= */

    public static function getAllClasses()
    {
        return static::query()->get();
    }

    public static function getClassById(int $id): ?self
    {
        return static::query()->find($id);
    }

    public static function createClass(array $data): int
    {
        $row = static::create($data);
        return (int) $row->id;
    }

    public static function updateClass(int $id, array $data): bool
    {
        return static::query()->whereKey($id)->update($data) >= 0;
    }

    public static function deleteClass(int $id): bool
    {
        $row = static::query()->find($id);
        if (!$row) return false;
        return (bool) $row->delete();
    }
}