<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class LeaveTypeSeeder extends Seeder
{
    protected array $types = [
        ['name' => 'Annual Leave', 'code' => 'AL', 'days_per_year' => 30, 'is_paid' => 1, 'description' => 'Standard annual vacation entitlement'],
        ['name' => 'Sick Leave', 'code' => 'SL', 'days_per_year' => 15, 'is_paid' => 1, 'description' => 'Medical or health-related absence'],
        ['name' => 'Casual Leave', 'code' => 'CL', 'days_per_year' => 7, 'is_paid' => 1, 'description' => 'Short-notice personal leave'],
        ['name' => 'Unpaid Leave', 'code' => 'UL', 'days_per_year' => 0, 'is_paid' => 0, 'description' => 'Leave without pay'],
    ];

    public function run(): void
    {
        $table = $this->db->table('leave_types');

        foreach ($this->types as $type) {
            $existing = $table->where('code', $type['code'])->get()->getRow();
            if ($existing) {
                continue;
            }

            $table->insert([
                'name'                => $type['name'],
                'code'                => $type['code'],
                'days_per_year'       => $type['days_per_year'],
                'is_paid'             => $type['is_paid'],
                'requires_approval'   => 1,
                'description'         => $type['description'],
                'status'              => 'active',
                'created_at'          => date('Y-m-d H:i:s'),
            ]);
        }
    }
}
