<?php

namespace App\Http\Controllers\V1;

use App\Helper\ByteDance;
use App\Helper\Kuaishou;
use App\Helper\UniPlatform\Bytedance\ByteDanceAPI;
use App\Helper\UniPlatform\Kuaishou\KuaishouAPI;
use App\Models\PayConfig;
use Dingo\Api\Routing\Helpers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Services\Base\ErrorCode;
use Request, Auth, Log;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, Helpers;

    public function success($data = null, $code = 0, $msg = null)
    {
        if (!$msg) $msg = trans('api.SUCCESS');

        $result = [
            'code' => $code,
            'msg'  => $msg,
            'data' => $data
        ];

        return response()->json($result);
    }

    public function error($msg = null, $code = 1, $data = null)
    {
        $result = [
            'code' => $code,
            'msg'  => $msg,
            'data' => $data
        ];

        return response()->json($result);
    }

    public function validatorError($arr, $code = 1, $message = '')
    {
        foreach ($arr as $val) {
            if ($val && $message == '') {
                $message = $val;
            }
        }
        if ($code !== 0 && ErrorCode::CLIENT_WRONG_PARAMS && empty($msg)) {
            $msg = ErrorCode::message($code);
        }
        $result = [
            'code' => $code,
            'msg'  => $msg,
            'data' => $data
        ];

        return response()->json($result);
    }
}
