<?php

namespace App\Models;

use CodeIgniter\Model;

class TaskOccurrenceModel extends Model
{
    protected $table            = 'task_occurrences';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'task_id',
        'occurrence_date',
        'occurrence_time',
        'status',
        'completed_at',
        'is_deleted',
    ];
    protected $useTimestamps = true;
    protected $dateFormat    = 'datetime';
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    public function findActive(int $occurrenceId): ?array
    {
        $row = $this->where('is_deleted', 0)->find($occurrenceId);

        return $row === null ? null : $row;
    }
}
