<?php

namespace Database\Seeders;

use App\Enums\OriginStatusType;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class BankSeeder extends Seeder
{
  /**
   * Run the database seeds.
   */
  public function run(): void
  {
    $jsonPath = resource_path('json/seeders/banks.json');
    $file = file_get_contents($jsonPath);
    $data = json_decode($file, true);

    $data = collect($data)->map(function ($bank) {
      $data = [
        'bi_fast' => $bank['bi_fast'] ? 1 : 0,
        'created_at' => now(),
        'updated_at' => now(),
      ];

      return [
        'code' => $bank['bank_code'],
        'name' => $bank['bank_name'],
        'limit_transfer_amount' => $bank['limit_transfer_amount'] ?? null,
        'status' => OriginStatusType::Active,
        ...$data
      ];
    })->toArray();

    DB::table('banks')->upsert($data, 'code');
  }
}