<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class SuplierSeeder extends Seeder
{
    public function run()
    {
        $suplier = [
            [
                'nama'       => 'Andi Pratama',
                'no_hp'      => '0812-3456-7890',
                'email'      => 'andi.pratama@mitrateknologi.co.id',
                'alamat'     => 'Jl. Gatot Subroto No. 18, Jakarta Selatan',
                'perusahaan' => 'PT Mitra Teknologi Nusantara',
            ],
            [
                'nama'       => 'Rina Kusuma',
                'no_hp'      => '0821-7788-3344',
                'email'      => 'rina.kusuma@sentraatk.com',
                'alamat'     => 'Jl. Ahmad Yani No. 42, Bandung',
                'perusahaan' => 'CV Sentra ATK Mandiri',
            ],
            [
                'nama'       => 'Budi Santoso',
                'no_hp'      => '0813-9021-5566',
                'email'      => 'budi.santoso@globaloffice.id',
                'alamat'     => 'Jl. HR Muhammad No. 76, Surabaya',
                'perusahaan' => 'PT Global Office Supply',
            ],
            [
                'nama'       => 'Siti Rahmawati',
                'no_hp'      => '0852-1188-9200',
                'email'      => 'siti.rahmawati@primagudang.co.id',
                'alamat'     => 'Jl. Ring Road Utara No. 9, Yogyakarta',
                'perusahaan' => 'PT Prima Gudang Sejahtera',
            ],
            [
                'nama'       => 'Hendra Wijaya',
                'no_hp'      => '0878-6400-2211',
                'email'      => 'hendra.wijaya@cahayalistrik.id',
                'alamat'     => 'Jl. Diponegoro No. 55, Semarang',
                'perusahaan' => 'CV Cahaya Listrik Abadi',
            ],
        ];

        foreach ($suplier as $item) {
            $exists = $this->db->table('suplier')
                ->where('email', $item['email'])
                ->get()
                ->getRowArray();

            if ($exists) {
                continue;
            }

            $this->db->table('suplier')->insert([
                'nama'       => $item['nama'],
                'no_hp'      => $item['no_hp'],
                'email'      => $item['email'],
                'alamat'     => $item['alamat'],
                'perusahaan' => $item['perusahaan'],
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ]);
        }
    }
}
