<?php
namespace App\Models;
use CodeIgniter\Model;

class PaymentModel extends Model
{
    protected $table          = 'payments';
    protected $primaryKey     = 'id';
    protected $useSoftDeletes = false;
    protected $deletedField   = 'deleted_at';
    protected $allowedFields  = ['company_id','invoice_id','amount','method','reference','stripe_charge_id','stripe_refund_id','paid_at','recorded_by','notes','created_at','updated_at','deleted_at'];

    public function forInvoice(int $invoiceId): array
    {
        return $this->where('invoice_id', $invoiceId)->whereNull('deleted_at')->orderBy('paid_at', 'DESC')->findAll();
    }
}
