<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Services\Client\UserService;
use Illuminate\Http\Request;

/**
 * 用户相关的API接口
 */
class UserController extends Controller
{
    protected UserService $service;

    public function __construct(UserService $service)
    {
        $this->service = $service;
    }

    /**
     * [用户管理] 发送验证码
     * 
     * 向指定手机号发送验证码
     * 
     * @bodyParam mobile string required 手机号码. Example: 13800138000
     * @response {
     *   "code": 200,
     *   "message": "验证码发送成功",
     *   "data": null
     * }
     */
    public function sendVerifyCode(Request $request)
    {
        $mobile = $request->input('mobile');
        return $this->service->sendVerifyCode($mobile);
    }

    /**
     * [用户管理] 用户登录
     * 
     * 使用手机号和验证码登录
     * 
     * @bodyParam mobile string required 手机号码. Example: 13800138000
     * @bodyParam code string required 验证码. Example: 123456
     * @response {
     *   "code": 200,
     *   "message": "登录成功",
     *   "data": {
     *     "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
     *     "user": {
     *       "id": 1,
     *       "mobile": "13800138000",
     *       "nickname": "用户昵称"
     *     }
     *   }
     * }
     */
    public function login(Request $request)
    {
        $mobile = $request->input('mobile');
        $code = $request->input('code');
        return $this->service->login($mobile, $code);
    }

    /**
     * [用户管理] 微信登录
     * 
     * 使用微信openid登录
     * 
     * @bodyParam openid string required 微信openid. Example: wx_123456789
     * @response {
     *   "code": 200,
     *   "message": "登录成功",
     *   "data": {
     *     "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
     *     "user": {
     *       "id": 1,
     *       "openid": "wx_123456789",
     *       "nickname": "微信昵称"
     *     }
     *   }
     * }
     */
    public function wxLogin(Request $request)
    {
        $openid = $request->input('openid');
        return $this->service->wxLogin($openid);
    }

    /**
     * [用户管理] 用户退出
     * 
     * 退出登录，清除token
     * 
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "退出成功",
     *   "data": null
     * }
     */
    public function logout()
    {
        return $this->service->logout();
    }

    /**
     * [用户管理] 获取用户信息
     * 
     * 获取当前用户的信息
     * 
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "id": 1,
     *     "mobile": "13800138000",
     *     "nickname": "用户昵称"
     *   }
     * }
     */
    public function info()
    {
        return $this->service->getUserInfo();
    }

    /**
     * [用户管理] 修改用户信息
     * 
     * 修改当前用户的信息
     * 
     * @authenticated
     * @bodyParam nickname string 用户昵称. Example: 用户昵称
     * @bodyParam avatar string 用户头像. Example: https://example.com/avatar.jpg
     * @response {
     *   "code": 200,
     *   "message": "修改成功",
     *   "data": null
     * }
     */
    public function updateInfo(Request $request)
    {
        $data = $request->all();
        return $this->service->updateUserInfo($data);
    }

    /**
     * [用户管理] 获取用户钱包
     * 
     * 获取当前用户的钱包信息
     * 
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "balance": 100.00,
     *     "freeze": 0.00
     *   }
     * }
     */
    public function wallet()
    {
        return $this->service->getUserWallet();
    }

    /**
     * [用户管理] 用户提现
     * 
     * 提现用户的余额
     * 
     * @authenticated
     * @bodyParam amount decimal 提现金额. Example: 100.00
     * @response {
     *   "code": 200,
     *   "message": "提现成功",
     *   "data": null
     * }
     */
    public function withdraw(Request $request)
    {
        $amount = $request->input('amount');
        return $this->service->withdraw($amount);
    }

    /**
     * [用户管理] 用户注销
     * 
     * 注销当前用户的账号
     * 
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "注销成功",
     *   "data": null
     * }
     */
    public function delete()
    {
        return $this->service->deleteAccount();
    }

    /**
     * [用户管理] 用户反馈
     * 
     * 提交用户的反馈信息
     * 
     * @authenticated
     * @bodyParam content string 反馈内容. Example: 这是一个反馈信息
     * @response {
     *   "code": 200,
     *   "message": "提交成功",
     *   "data": null
     * }
     */
    public function feedback(Request $request)
    {
        $content = $request->input('content');
        return $this->service->feedback($content);
    }

    /**
     * [用户管理] 申请成为技师
     * 
     * 申请成为技师
     * 
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "申请成功",
     *   "data": null
     * }
     */
    public function applyCoach()
    {
        return $this->service->applyCoach();
    }
}