<?php
namespace My\Component\GrafikKeuangan\Administrator\Table;

defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver;

class GrafikKeuangan extends Table
{
	public function __construct(DatabaseDriver $db)
	{
		parent::__construct('#__grafik_keuangan', 'id', $db);
		$this->setColumnAlias('published', 'state');
	}

	public function publish($pks = null, $state = 1, $userId = 0)
	{
		return parent::publish($pks, $state, $userId);
	}

	public function check()
	{
		// Sanitize numeric fields to ensure they are not empty strings
		$numericFields = [
			'pagu_51',
			'realisasi_51',
			'pagu_52',
			'realisasi_52',
			'pagu_53',
			'realisasi_53',
			'pagu_posbakum',
			'realisasi_posbakum',
			'pagu_prodeo',
			'realisasi_prodeo'
		];

		foreach ($numericFields as $field) {
			if (empty($this->$field)) {
				$this->$field = 0;
			}
		}

		return parent::check();
	}
}
