<?php

namespace App\Services;

use Illuminate\Support\Facades\DB;
use App\Services\DataService;

class DeviceDataService extends DataService
{


    /**
     * Clears a fcm foken for a user device
     * 
     * @param int $userId
     * @param string $token
     * 
     * @return int the number of affected records
     */
    public function clearDeviceFcmToken(int $userId, string $token): int
    {
        if (empty($token)) {
            return 0;
        }

        return DB::table('devices')
            ->where('user_id', $userId)
            ->where('fcm_token', $token)
            ->update(['fcm_token' => null]);
    }
}
