<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class DepartmentSeeder extends Seeder
{
    public function run(): void
    {
        $existing = $this->db->table('departments')->where('name', 'Administration')->get()->getRow();
        if ($existing) {
            return;
        }

        $branch = $this->db->table('branches')->where('code', 'HQ')->get()->getRow();

        $this->db->table('departments')->insert([
            'branch_id'  => $branch->id ?? null,
            'name'       => 'Administration',
            'status'     => 'active',
            'created_at' => date('Y-m-d H:i:s'),
            'updated_at' => date('Y-m-d H:i:s'),
        ]);
    }
}
