<?php

namespace Database\Seeders;

use App\Models\Employee;
use App\Models\Payroll;
use App\Models\PayrollPeriod;
use Illuminate\Database\Seeder;

class PayrollSeeder extends Seeder
{
    public function run(): void
    {
        $period = PayrollPeriod::query()->latest('id')->first();

        if ($period === null) {
            return;
        }

        Employee::query()->each(function (Employee $employee) use ($period): void {
            Payroll::factory()->create([
                'payroll_period_id' => $period->id,
                'employee_id' => $employee->id,
                'base_salary' => $employee->base_salary ?? 0,
                'total_amount' => $employee->base_salary ?? 0,
            ]);
        });
    }
}
