<?php namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class LoanProductsSeeder extends Seeder
{
    public function run()
    {
        $db = \Config\Database::connect();
        $builder = $db->table('loan_products');

        $existing = $builder->where('slug','payday')->orWhere('slug','weekly')->orWhere('slug','monthly')->get()->getResultArray();
        if (!empty($existing)) return;

        $now = date('Y-m-d H:i:s');
        $builder->insertBatch([
            ['name'=>'Payday','slug'=>'payday','base_interest'=>20.0000,'processing_fee_pct'=>2.0,'late_fee'=>50,'min_amount'=>100,'max_amount'=>50000,'created_at'=>$now,'updated_at'=>$now],
            ['name'=>'Weekly','slug'=>'weekly','base_interest'=>15.0000,'processing_fee_pct'=>1.5,'late_fee'=>25,'min_amount'=>500,'max_amount'=>100000,'created_at'=>$now,'updated_at'=>$now],
            ['name'=>'Monthly','slug'=>'monthly','base_interest'=>12.0000,'processing_fee_pct'=>1.0,'late_fee'=>100,'min_amount'=>1000,'max_amount'=>1000000,'created_at'=>$now,'updated_at'=>$now],
        ]);
    }
}
