<?php

namespace App\Models;

use CodeIgniter\Model;

class WalletTransactionModel extends Model
{
    protected $table         = 'wallet_transactions';
    protected $useTimestamps = false;
    protected $allowedFields = ['wallet_id', 'type', 'amount', 'balance_after', 'reference_type', 'reference_id', 'note', 'created_at'];

    public function historyFor(int $walletId, int $page = 1, int $perPage = 20): array
    {
        $offset = ($page - 1) * $perPage;
        return $this->where('wallet_id', $walletId)->orderBy('created_at', 'DESC')->findAll($perPage, $offset);
    }
}
