<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;
use App\Models\ValueSet\ValueSetModel;

class LocationSeeder extends Seeder {
  
  protected array $map = [];

  public function run() {
    $now = date('Y-m-d H:i:s');
    $vsModel = new ValueSetModel();
    $rows = $vsModel->select("VID, VSetID, VValue")->findAll();
    $vs = [];
    foreach ($rows as $row) {
      $vs[$row['VSetID']][$row['VValue']] = $row['VID'];
    }
    
    // location
    $data = [
      ['LocationID' => 1, 'LocCode' => 'QLOC', 'LocFull' => 'Dummy Location', 'LocType' => $vs[12]['ROOM'], 'Description' => 'Location made for dummy testing', 'CreateDate' => "$now" ],
      ['LocationID' => 2, 'LocCode' => 'DEFLOC', 'LocFull' => 'Default Location', 'LocType' => $vs[12]['ROOM'], 'Description' => 'Default location', 'CreateDate' => "$now" ]
    ];
    $this->db->table('location')->insertBatch($data);
    $data = [
      ['LocationID' => 1, 'Street1' => 'Jalan Nginden', 'Street2' => 'Intan Raya', 'City' => 'Surabaya', 'Province' => 'East Java', 'PostCode' => '60222', 'CreateDate' => "$now"],
      ['LocationID' => 2, 'Street1' => 'Jalan ', 'Street2' => 'Jalan jalan', 'City' => 'Depok', 'Province' => 'DKI Jakarta', 'PostCode' => '10123', 'CreateDate' => "$now"]
    ];
    $this->db->table('locationaddress')->insertBatch($data);

  }
}