<?php

namespace App\Models\Magento;

use CodeIgniter\Model;

class CommandeModel extends Model
{
    protected $DBGroup = 'magento';
    protected $table = 'sales_order';
    protected $primaryKey = 'entity_id';
    protected $allowedFields = [];

    /**
     * Retourne le nombre total de commandes.
     */
    public function countTotal(): int
    {
        return $this->countAllResults();
    }

    /**
     * Retourne les dernières commandes.
     */
    public function getRecent(int $limit = 10): array
    {
        return $this->orderBy('created_at', 'DESC')
                    ->limit($limit)
                    ->findAll();
    }
}
