<?php

declare(strict_types=1);

namespace WorkforceOS\Services;

final class HrmModuleService
{
    public function leaves(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['pending' => 14, 'approved_today' => 8, 'rejected_today' => 2, 'encashment_due' => 5],
            'types' => ['Casual Leave', 'Sick Leave', 'Earn Leave', 'Maternity Leave', 'Unpaid Leave'],
            'requests' => [
                ['employee' => 'EMP-1001', 'type' => 'Sick Leave', 'days' => 2, 'status' => 'pending'],
                ['employee' => 'EMP-1007', 'type' => 'Earn Leave', 'days' => 5, 'status' => 'approved'],
                ['employee' => 'EMP-1022', 'type' => 'Casual Leave', 'days' => 1, 'status' => 'pending'],
            ],
        ];
    }

    public function holidays(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'weekends' => ['Friday'],
            'holidays' => [
                ['name' => 'Eid-ul-Adha', 'date' => '2026-06-17', 'branch' => 'All Branches', 'type' => 'festival'],
                ['name' => 'Factory Maintenance Off', 'date' => '2026-06-21', 'branch' => 'Gazipur Plant', 'type' => 'branch'],
                ['name' => 'Victory Day', 'date' => '2026-12-16', 'branch' => 'All Branches', 'type' => 'government'],
            ],
            'ot_rules' => ['holiday_multiplier' => 2.0, 'weekend_multiplier' => 1.5],
        ];
    }

    public function finance(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['income' => 4850000, 'expense' => 3275000, 'payroll_expense' => 26850000, 'loan_balance' => 940000],
            'transactions' => [
                ['type' => 'expense', 'category' => 'Payroll', 'amount' => 26850000, 'date' => '2026-05-25'],
                ['type' => 'income', 'category' => 'Service Income', 'amount' => 4850000, 'date' => '2026-05-20'],
                ['type' => 'expense', 'category' => 'Device Maintenance', 'amount' => 75000, 'date' => '2026-05-18'],
            ],
        ];
    }

    public function tasks(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['open' => 42, 'overdue' => 6, 'completed_today' => 18],
            'tasks' => [
                ['title' => 'Verify missing punches', 'assigned_to' => 'HR Team', 'deadline' => '2026-05-27', 'status' => 'in_progress'],
                ['title' => 'Approve payroll draft', 'assigned_to' => 'Finance Manager', 'deadline' => '2026-05-28', 'status' => 'pending'],
                ['title' => 'Sync new employees to UFace', 'assigned_to' => 'IT Admin', 'deadline' => '2026-05-26', 'status' => 'overdue'],
            ],
        ];
    }

    public function contracts(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['active' => 612, 'expiring_30_days' => 27, 'renewal_pending' => 13],
            'contracts' => [
                ['employee' => 'EMP-1001', 'contract_no' => 'CNT-2026-001', 'expires_on' => '2026-06-12', 'status' => 'renewal_pending'],
                ['employee' => 'EMP-1007', 'contract_no' => 'CNT-2026-019', 'expires_on' => '2026-07-01', 'status' => 'active'],
                ['employee' => 'EMP-1022', 'contract_no' => 'CNT-2026-088', 'expires_on' => '2026-06-05', 'status' => 'expiring'],
            ],
        ];
    }

    public function disciplinary(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['warnings' => 9, 'penalties' => 4, 'suspensions' => 1],
            'records' => [
                ['employee' => 'EMP-1007', 'type' => 'warning', 'subject' => 'Repeated late attendance', 'penalty' => 0],
                ['employee' => 'EMP-1022', 'type' => 'penalty', 'subject' => 'Missing punch policy breach', 'penalty' => 500],
                ['employee' => 'EMP-1040', 'type' => 'suspension', 'subject' => 'Policy violation', 'penalty' => 0],
            ],
        ];
    }

    public function security(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'controls' => [
                ['name' => 'Role based permission', 'status' => 'enabled'],
                ['name' => 'IP whitelist', 'status' => 'enabled'],
                ['name' => 'Two factor authentication', 'status' => 'optional'],
                ['name' => 'Audit log', 'status' => 'enabled'],
                ['name' => 'Router IP whitelist', 'status' => 'enabled'],
            ],
            'activity' => [
                ['user' => 'admin@acme.test', 'event' => 'login', 'ip' => '103.22.45.10', 'time' => '09:12'],
                ['user' => 'hr@acme.test', 'event' => 'employee.updated', 'ip' => '103.22.45.11', 'time' => '09:18'],
                ['user' => 'finance@acme.test', 'event' => 'payroll.preview', 'ip' => '103.22.45.12', 'time' => '09:25'],
            ],
        ];
    }

    public function settings(array $tenant): array
    {
        return [
            'tenant' => $tenant,
            'settings' => [
                'currency' => $tenant['currency'],
                'timezone' => $tenant['timezone'],
                'time_format' => '12h',
                'payroll_lock_day' => 28,
                'attendance_auto_absent_time' => '23:59',
                'smtp' => 'configured',
                'sms_gateway' => 'configured',
                'whatsapp_api' => 'pending',
            ],
        ];
    }
}
