<?php

namespace App\Models;

use CodeIgniter\Model;

class Company extends Model
{
    /**
     * table name
     * @var string
     */
    protected $table = 'company';
    // List all the fields that are allowed to be updated or inserted
    protected $allowedFields = [
        'company_name', 'service_charge_value', 'vat_charge_value', 'address', 'phone', 'phone2', 'NIF', 'STAT', 'country', 'message', 'currency',
    ];

    /**
     * Get company data by id or all
     * @param mixed $id
     * @return array<float|int|object|string|null>|object|null
     */
    public function getCompanyData($id = null)
    {
        if ($id) {
            return $this->find($id); // Find by id
        }
        return null; // Return null if no id is provided
    }

    /**
     * Update company data
     * @param mixed $data
     * @param mixed $id
     * @return bool
     */
    public function updateCompany($data, $id)
    {
        if ($data && $id) {
            return $this->update($id, $data); // Update data by id
        }
        return false;
    }
}