<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\AccountsInfo;
use App\Models\AccountsSource;
use App\Util;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class AdjustController extends Controller
{
    public function report(Request $request)
    {
       Util::WriteLog('adjust_report', $request->all());
        $adID = $request->input('ad_id');
        $campaignName = $request->input('campaign_name');

        $AdChannel = 0;
        preg_match('/\*\d+/', $campaignName, $result);
        if (isset($result[0])) {
            $AdChannel = explode('*', $result[0])[1] ?? 0;
        }
//        $accountInfo = AccountsInfo::lock('with(nolock)')->where('Accounts', $adID)->first();
//        if (!$accountInfo) {
//            Log::info('adjust_report account not found', [
//                'adid' => $adID
//            ]);
//            return apiReturnFail(__('messages.api.adjust.not_found'));
//        }
//        $accountSource = AccountsSource::where('UserID', $accountInfo->UserID)->lock('with(nolock)')->first();
//        if (!$accountSource) {
//            $accountSource = new AccountsSource();
//            $accountSource->UserID = $accountInfo->UserID;
//            $accountSource->Source = $campaignName;
//            $accountSource->AdChannel = $AdChannel;
//            $accountSource->save();
//        }

        return apiReturnSuc();
    }
}
