<?php

namespace App\Http\Controllers\Webhook;

use App\Services\Webhook\WebhookService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;

class WebhookController extends BaseController
{
    private $webhookService;

    public function __construct(
        WebhookService $webhookService
    )
    {
        $this->webhookService = $webhookService;
    }

    /**
     * 抖音im回调
     *
     * @param Request $request
     * @return JsonResponse
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function douYinIm(Request $request)
    {
        $data = $request->all();
        dLog('webhook')->info('douYinIm-params', $data);

        // 根据event事件区分
        $event  = trim(getProp($data, 'event'));
        $result = $this->webhookService->handleDouYinEvent($event, $data);
        return response()->json($result);
    }
}