<?php

namespace App\Http\Controllers\Client;

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

/**
 * @group 用户端
 *
 * 技师定位相关的API接口
 */
class CoachLocationController extends Controller
{
    protected $coachLocationService;

    /**
     * CoachLocationController constructor.
     */
    public function __construct(CoachLocationService $coachLocationService)
    {
        $this->coachLocationService = $coachLocationService;
    }

    /**
     * 获取定位列表
     *
     * @authenticated
     *
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": [
     *     {
     *       "id": 1,
     *       "type": "home",
     *       "latitude": 34.0522,
     *       "longitude": -118.2437,
     *       "city": "Los Angeles",
     *       "district": "Downtown",
     *       "location": "123 Main St",
     *       "area_code": "90001"
     *     }
     *   ]
     * }
     */
    public function index()
    {
        return $this->coachLocationService->getAllLocations();
    }

    /**
     * 创建定位
     *
     * @authenticated
     *
     * @bodyparam type int required 类型. example: 1
     * @bodyparam latitude float required 纬度. example: 39.904989
     * @bodyparam longitude float required 经度. example: 116.405285
     * @bodyparam city string required 市. example: los angeles
     * @bodyparam district string required 区. example: downtown
     * @bodyparam location string required 详细地址. example: 123 main st
     * @bodyparam area_code string required 区域编码. example: 90001
     *
     * @response {
     *   "code": 200,
     *   "message": "创建成功",
     *   "data": {
     *     "id": 1,
     *     "type": "home",
     *     "latitude": 34.0522,
     *     "longitude": -118.2437,
     *     "city": "los angeles",
     *     "district": "downtown",
     *     "location": "123 main st",
     *     "area_code": "90001"
     *   }
     * }
     */
    public function store(Request $request)
    {
        return $this->coachLocationService->createLocation($request->all());
    }

    /**
     * 删除定位
     *
     * @authenticated
     *
     * @bodyParam coach_id int required 技师ID. Example: 1
     * @bodyParam type string required 类型. Example: home
     *
     * @response {
     *   "code": 200,
     *   "message": "删除成功",
     *   "data": null
     * }
     */
    public function destroy(Request $request)
    {
        $type = $request->type;
        $coachId = $request->coach_id;

        return $this->coachLocationService->deleteLocation($coachId, $type);
    }
}