<?php

namespace App\Models;

use CodeIgniter\Model;

class DeliveryNoteModel extends Model
{
    protected $table = 'delivery_notes';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $useAutoIncrement = true;
    protected $protectFields = true;
    protected $allowedFields = [
        'folio', 'template_id', 'client_id', 'title', 'body_html',
        'field_values_json', 'status', 'verify_token', 'signed_at',
    ];
    protected $useTimestamps = true;

    public function values(array $note): array
    {
        $values = json_decode((string) ($note['field_values_json'] ?? '{}'), true);
        return is_array($values) ? $values : [];
    }
}
