<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Helpers\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class MobileLogController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'level' => 'required|string|in:debug,info,warning,error,critical',
            'message' => 'required|string',
            'context' => 'nullable|array',
        ]);

        $context = [
            'timestamp' => now()->format('Y-m-d H:i:s'),
            'user_id' => auth()->id() ?? 'guest',
            'ip' => $request->ip(),
            'user_agent' => $request->userAgent(),
            'context' => $request->context,
        ];

        $message = $request->message.' Context: '.json_encode($context);

        Log::channel('mobile')->log($request->level, $message);

        return ApiResponse::success(null, 'Log recorded');
    }
}
