<?php

namespace App\Models;

use CodeIgniter\Model;

class TrainModel extends Model
{
    protected $table      = 'c_train';
    protected $primaryKey = 'train_id';

    protected $allowedFields = [
        'plan_id',
        'class',
        'train_no',
        'from_station',
        'to_station',
        'date',
        'time',
        'comments',
        'is_this_exceptional',
        'created_by',
        'updated_by',
        'is_active'
    ];

    protected $useTimestamps = false;
    protected $createdField  = 'created_on';
    protected $updatedField  = 'updated_on';

    /**
     * Get active train bookings
     */
    public function getActiveTrains()
    {
        return $this->where('is_active', 1)->findAll();
    }

    /**
     * Get train bookings for a specific plan
     */
    public function getTrainsByPlan($planId)
    {
        return $this->where('plan_id', $planId)->findAll();
    }
}
