<?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;
    }

    /**
     * [用户管理] 获取用户信息
     *
     * 获取当前用户的信息
     *
     * @authenticated
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "id": 1,
     *     "mobile": "13800138000",
     *     "nickname": "用户昵称"
     *   }
     * }
     */
    public function show()
    {
        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 update(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
     * @bodyParam type string 提现方式. Example: wechat
     * @bodyParam area_code string 行政区划代码. Example: 330100
     * @response {
     *   "code": 200,
     *   "message": "提现成功",
     *   "data": null
     * }
     */
    public function withdraw(Request $request)
    {
        $amount = $request->input('amount');
        $type = $request->input('type', 'wechat');
        $area_code = $request->input('area_code', '');
        return $this->service->withdraw($amount, $type, $area_code);
    }

    /**
     * [用户管理] 用户反馈
     *
     * 提交用户的反馈信息
     *
     * @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
     * @bodyParam mobile string 手机号. Example: 13800138000
     * @bodyParam gender string 性别. Example: male
     * @bodyParam work_years string 工作年限. Example: 5
     * @bodyParam intention_city string 意向城市. Example: 杭州
     * @response {
     *   "code": 200,
     *   "message": "申请成功",
     *   "data": null
     * }
     */
    public function applyCoach(Request $request)
    {
        $mobile = $request->input('mobile');
        $gender = $request->input('gender');
        $work_years = $request->input('work_years');
        $intention_city = $request->input('intention_city');
        return $this->service->applyCoach($mobile, $gender, $work_years, $intention_city);
    }
}
