<?php

namespace App\Models;

use CodeIgniter\Model;

class PaymentMethodModel extends Model
{
    protected $table      = 'payment_methods';
    protected $primaryKey = 'id_payment_method';
    protected $returnType = 'array';

    protected $useTimestamps = false;

    protected $allowedFields = [
        'nama_metode',
        'kode',
        'keterangan',
        'is_active'
    ];

    protected $validationRules = [
        'nama_metode' => 'required|min_length[2]'
    ];

    /**
     * Semua metode aktif
     */
    public function active()
    {
        return $this->where('is_active', 1)
                    ->orderBy('nama_metode', 'ASC')
                    ->findAll();
    }

    /**
     * Cari metode berdasarkan nama
     */
    public function getByName(string $name)
    {
        return $this->where('nama_metode', $name)
                    ->first();
    }
}
