<?php

declare(strict_types=1);

namespace WorkforceOS\Services;

final class SaasOperationsService
{
    public function billing(): array
    {
        return [
            'summary' => [
                'monthly_recurring_revenue' => 1285000,
                'outstanding_due' => 184000,
                'paid_this_month' => 940000,
                'renewals_next_7_days' => 6,
            ],
            'invoices' => [
                ['invoice_no' => 'INV-2026-0501', 'client' => 'Acme Industries Ltd.', 'amount' => 49900, 'due_date' => '2026-06-01', 'status' => 'paid'],
                ['invoice_no' => 'INV-2026-0502', 'client' => 'North Textile Group', 'amount' => 12900, 'due_date' => '2026-06-03', 'status' => 'due'],
                ['invoice_no' => 'INV-2026-0503', 'client' => 'Metro Logistics', 'amount' => 12900, 'due_date' => '2026-05-12', 'status' => 'overdue'],
            ],
            'payments' => [
                ['client' => 'Acme Industries Ltd.', 'method' => 'bank', 'amount' => 49900, 'paid_at' => '2026-05-21 11:22'],
                ['client' => 'Prime Foods', 'method' => 'card', 'amount' => 0, 'paid_at' => 'trial'],
            ],
        ];
    }

    public function monitoring(): array
    {
        return [
            'summary' => [
                'online_clients' => 16,
                'online_devices' => 94,
                'live_logs_today' => 18452,
                'active_employees' => 8124,
            ],
            'device_status' => [
                ['serial' => 'F22-HQ-01', 'client' => 'Acme Industries Ltd.', 'branch' => 'Head Office', 'status' => 'online', 'last_seen' => '1 minute ago'],
                ['serial' => 'UFACE-GZ-02', 'client' => 'Acme Industries Ltd.', 'branch' => 'Gazipur Plant', 'status' => 'online', 'last_seen' => '4 minutes ago'],
                ['serial' => 'K40-CTG-01', 'client' => 'Acme Industries Ltd.', 'branch' => 'Chattogram Depot', 'status' => 'offline', 'last_seen' => '42 minutes ago'],
            ],
            'events' => [
                ['time' => '09:32:10', 'type' => 'attendance.log', 'message' => 'EMP-1001 checked in using fingerprint.'],
                ['time' => '09:33:14', 'type' => 'device.online', 'message' => 'UFACE-GZ-02 reconnected to cloud service.'],
                ['time' => '09:34:01', 'type' => 'payroll.job', 'message' => 'Payroll preview generated for Acme Industries Ltd.'],
            ],
        ];
    }

    public function registrationControl(): array
    {
        return [
            'settings' => [
                'self_registration' => 'disabled',
                'manual_approval' => 'enabled',
                'trial_package' => 'Trial',
                'default_status' => 'pending_approval',
            ],
            'pending_requests' => [
                ['company' => 'Delta Apparel Ltd.', 'email' => 'owner@delta.test', 'employees' => 320, 'requested_package' => 'Business', 'status' => 'pending'],
                ['company' => 'Green Agro Foods', 'email' => 'admin@greenagro.test', 'employees' => 85, 'requested_package' => 'Trial', 'status' => 'pending'],
            ],
        ];
    }

    public function transfers(array $tenant): array
    {
        return [
            'tenant_id' => $tenant['id'],
            'summary' => ['pending' => 5, 'approved_this_month' => 18, 'branch_transfers' => 9, 'shift_transfers' => 14],
            'requests' => [
                ['employee' => 'EMP-1007', 'type' => 'branch', 'from' => 'Gazipur Plant', 'to' => 'Head Office', 'effective_date' => '2026-06-01', 'status' => 'pending'],
                ['employee' => 'EMP-1022', 'type' => 'department', 'from' => 'Production', 'to' => 'Quality Control', 'effective_date' => '2026-05-29', 'status' => 'approved'],
                ['employee' => 'EMP-1030', 'type' => 'shift', 'from' => 'General Shift', 'to' => 'Night Shift', 'effective_date' => '2026-05-27', 'status' => 'pending'],
            ],
        ];
    }
}
