<?php

namespace App\Http\Responses;

class ApiResponse
{
    public static function success(mixed $data = null, string $message = 'success'): array
    {
        return [
            'code' => 0,
            'message' => $message,
            'data' => $data,
            'timestamp' => time(),
        ];
    }

    public static function error(int $code, string $message, mixed $data = null): array
    {
        return [
            'code' => $code,
            'message' => $message,
            'data' => $data,
            'timestamp' => time(),
        ];
    }

    public static function paginate($paginator, string $message = 'success'): array
    {
        return [
            'code' => 0,
            'message' => $message,
            'data' => [
                'items' => $paginator->items(),
                'pagination' => [
                    'current_page' => $paginator->currentPage(),
                    'per_page' => $paginator->perPage(),
                    'total' => $paginator->total(),
                    'last_page' => $paginator->lastPage(),
                ],
            ],
            'timestamp' => time(),
        ];
    }
}
