<?php

namespace App\Libraries\DBMigration\Process;

use App\Entities\Part\SWITCHEntity;
use CodeIgniter\Database\BaseConnection;

class SwitchCodeProcess implements MigrationProcessInterface
{
  private $db;
  public function __construct(BaseConnection $db)
  {
    $this->db = $db;
  }
  public function process(array $row, int $cnt): void
  {
    $temps = [];
    $temps['code'] = trim($row['service_sw']);
    $temps['status'] = SWITCHEntity::DEFAULT_STATUS; // Assuming SWITCHEntity has a STATUS_DEFAULT constant
    if (!$this->db->table('switchinfo')->insert($temps)) {
      throw new \Exception($this->db->error()['message']);
    }
    echo "{$cnt} -> {$temps['code']} SWITCHCODE 완료.\n";
  }
}
