<?php

namespace App\Models;

use CodeIgniter\Model;

class EventModel extends Model
{
    protected $table         = 'events';
    protected $primaryKey    = 'id';
    protected $returnType = 'array';
    protected $allowedFields = ['title', 'slug', 'description', 'location', 'event_date', 'event_time', 'sort_order', 'status', 'show'];
    protected $useTimestamps = true;

    public function getUpcoming(int $limit = 4)
    {
        return $this->where('event_date >=', date('Y-m-d'))
                    ->orWhere('status', 'ongoing')
                    ->orderBy('event_date', 'ASC')
                    ->findAll($limit);
    }
}
