<?php

namespace App\Http\Controllers\admin;

use App\Constants\HttpStatus;
use App\Http\Controllers\Controller;
use App\Services\RoomService;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use App\Services\UserService;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;


class User extends Controller
{

    /**
     * @description: 分页数据查询
     * @param {Request} $request
     * @return {*}
     */




    /**
     * @api {get} /admin/user 会员列表
     * @apiGroup 会员管理
     *
     * @apiUse result
     * @apiUse header
     * @apiVersion 1.0.0
     *
     * @apiParam {int} [page=1]
     * @apiParam {int} [limit=10]
     * @apiParam {string} [first_name] 用户昵称
     * @apiParam {string} [member_id] 房主 tg会员ID
     * @apiParam {string} [game_id] 游戏ID
     *
     * @apiSuccess (data) {Object} data
     * @apiSuccess (data) {int} data.total 数量
     * @apiSuccess (data) {Object[]} data.data 列表
     * @apiSuccess (data) {int} data.data.id
     * @apiSuccess (data) {int} data.data.member_id tg会员id
     * @apiSuccess (data) {string} data.data.first_name 昵称
     * @apiSuccess (data) {string} data.data.usdt 用户usdt钱包地址
     * @apiSuccess (data) {string} data.data.game_id 游戏ID
     * @apiSuccess (data) {string} data.data.updated_at
     * @apiSuccess (data) {string} data.data.created_at
     */
    public function index()
    {

        try {
            request()->validate([
                'game_id' => ['nullable', 'string', 'min:1'],
                'member_id' => ['nullable', 'string', 'min:1'],
                'first_name' => ['nullable', 'string', 'min:1']
            ]);
            $search = request()->all();
            $result = UserService::paginate($search);
        } catch (ValidationException $e) {
            return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
        } catch (Exception $e) {
            return $this->error(intval($e->getCode()));
        }
        return $this->success($result);


//        $search = $request->all();
//        $result = UserService::paginate($search);
//        return $this->success($result);
    }

    /**
     * @description: 创建
     * @param {Request} $request
     * @return {*}
     */
    public function store(Request $request)
    {

    }

    /**
     * @description: 更新
     * @param {Request} $request
     * @return {*}
     */
    public function update(Request $request)
    {

    }

}
