<?php

declare(strict_types=1);

namespace WorkforceOS\Services;

final class PayrollService
{
    public function preview(array $tenant, array $payload): array
    {
        $basic = (float) ($payload['basic_salary'] ?? 30000);
        $allowances = (float) ($payload['allowances'] ?? 7000);
        $overtime = (float) ($payload['overtime'] ?? 1800);
        $bonus = (float) ($payload['bonus'] ?? 0);
        $deductions = (float) ($payload['deductions'] ?? 1250);
        $latePenalty = (float) ($payload['late_penalty'] ?? 500);

        return [
            'tenant_id' => $tenant['id'],
            'period' => $payload['period'] ?? date('Y-m'),
            'earnings' => [
                'basic_salary' => $basic,
                'allowances' => $allowances,
                'overtime' => $overtime,
                'bonus' => $bonus,
            ],
            'deductions' => [
                'standard' => $deductions,
                'late_penalty' => $latePenalty,
            ],
            'gross_salary' => $basic + $allowances + $overtime + $bonus,
            'net_salary' => $basic + $allowances + $overtime + $bonus - $deductions - $latePenalty,
            'status' => 'preview',
        ];
    }
}
