<?php

namespace App\Http\Controllers\Api\Mobile;

use App\Http\Controllers\Controller;
use App\Services\PushNotificationService;
use Illuminate\Http\Request;

class DeviceTokenController extends Controller
{
    public function store(Request $request, PushNotificationService $push)
    {
        $request->validate([
            'fcm_token' => 'required|string|min:20|max:512',
            'platform' => 'nullable|string|max:20',
        ]);

        $customer = $request->user();
        $push->registerToken('customer', (int) $customer->id, $request->fcm_token, $request->platform);

        return response()->json(['status' => 'success', 'message' => 'Device registered for notifications']);
    }

    public function destroy(Request $request, PushNotificationService $push)
    {
        $request->validate(['fcm_token' => 'required|string']);

        $push->removeToken('customer', $request->fcm_token);

        return response()->json(['status' => 'success']);
    }
}
