<?php

namespace App\Services;

use App\Models\DeviceToken;
use Illuminate\Support\Facades\Auth;

class DeviceTokenService
{
    public function register(array $data): DeviceToken
    {
        return DeviceToken::updateOrCreate(
            ['token' => $data['token']],
            [
                'user_id'  => Auth::id(),
                'platform' => $data['platform'],
                'app_type' => $data['app_type'],
                'active'   => true,
            ]
        );
    }

    public function remove(string $token): void
    {
        DeviceToken::where('token', $token)
            ->where('user_id', Auth::id())
            ->update(['active' => false]);
    }
}
