<?php


namespace App\Http\Controllers\admin;


use App\Constants\HttpStatus;
use App\Http\Controllers\Controller;
use App\Services\BalanceLogService;
use Illuminate\Validation\ValidationException;
use Exception;

class Balance extends Controller
{

    /**
     * @api {get} /admin/balance/log 钱包记录
     * @apiGroup 钱包相关
     *
     * @apiUse result
     * @apiUse header
     * @apiVersion 1.0.0
     *
     * @apiParam {int} [page=1]
     * @apiParam {int} [limit=10]
     * @apiParam {string} [member_id] tg会员ID
     *
     *
     * @apiSuccess (data) {Object} data
     * @apiSuccess (data) {int} data.total 数量
     * @apiSuccess (data) {Object[]} data.data 列表
     * @apiSuccess (data) {int} data.data.id
     * @apiSuccess (data) {string} data.data.room_id 房间号，如果是结算
     * @apiSuccess (data) {string} data.data.member_id  tg会员id
     * @apiSuccess (data) {string} data.data.amount 变动金额
     * @apiSuccess (data) {string} data.data.before_balance 变动前余额
     * @apiSuccess (data) {string} data.data.after_balance 变动后余额
     * @apiSuccess (data) {string} data.data.change_type 变动类型，如 "充值"、"提现"、"结算" 等
     * @apiSuccess (data) {int} data.data.related_id 相关ID
     * @apiSuccess (data) {string} data.data.updated_at
     * @apiSuccess (data) {string} data.data.created_at
     */
    public function log()
    {
        try {
            request()->validate([
                'member_id' => ['nullable', 'string', 'min:1']
            ]);
            $search = request()->all();
            $result = BalanceLogService::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);
    }
}