<?php

declare(strict_types=1);

namespace App\Models;

use CodeIgniter\Model;

class DocumentChunkModel extends Model
{
    protected $table            = 'document_chunks';
    protected $primaryKey       = 'id';
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = [
        'document_id',
        'chunk_index',
        'content_text',
        'embedding',
    ];
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = 'updated_at';
    protected $deletedField     = 'deleted_at';
    protected $validationRules  = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;

    public function getEmbeddings(): array
    {
        $builder = $this->builder();
        $builder->select('id, document_id, chunk_index, content_text, embedding');
        $builder->where('embedding IS NOT NULL', null, false);
        $builder->where('embedding !=', '');
        return $builder->get()->getResultArray();
    }
}
