<?php

namespace App\Http\Controllers\Client;

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

/**
 * 项目管理相关的API接口
 */
class ProjectController extends Controller
{
    protected ProjectService $service;

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

    /**
     * [项目管理] 获取项目列表
     *
     * 根据区域代码获取项目列表
     *
     * @authenticated
     *
     * @queryParam area_code string 区域代码. Example: 330100
     * @queryParam project_cate_id integer 项目分类ID. Example: 1
     *
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "current_page": 1,
     *     "data": [
     *       {
     *         "id": 1,
     *         "name": "项目名称",
     *         "description": "项目描述",
     *         "price": "100.00",
     *         "duration": 60,
     *         "category": {
     *           "id": 1,
     *           "name": "分类名称"
     *         }
     *       }
     *     ],
     *     "total": 10,
     *     "per_page": 10
     *   }
     * }
     */
    public function index(Request $request)
    {
        $areaCode = $request->input('area_code');
        $projectCateId = $request->input('project_cate_id');

        return $this->service->getProjectList($areaCode, $projectCateId);
    }

    /**
     * [项目管理] 获取项目详情
     *
     * 获取指定项目的详细信息
     *
     * @authenticated
     *
     * @urlParam id integer required 项目ID. Example: 1
     *
     * @queryParam area_code string required 区域代码. Example: 330100
     *
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "id": 1,
     *     "name": "项目名称",
     *     "description": "项目描述",
     *     "price": "100.00",
     *     "duration": 60,
     *     "category": {
     *       "id": 1,
     *       "name": "分类名称"
     *     },
     *     "agent": {
     *       "id": 1,
     *       "name": "代理商名称",
     *       "contact": "联系人",
     *       "mobile": "13800138000"
     *     }
     *   }
     * }
     * @response 404 {
     *   "code": 404,
     *   "message": "项目不存在"
     * }
     * @response 400 {
     *   "code": 400,
     *   "message": "该区域暂无代理商"
     * }
     */
    public function detail(Request $request, $id)
    {
        $areaCode = $request->input('area_code');

        return $this->service->getProjectDetail($id, $areaCode);
    }

    /**
     * [项目管理] 获取技师项目列表
     *
     * 获取指定技师已开通的项目列表
     *
     * @authenticated
     *
     * @queryParam coach_id integer required 技师ID. Example: 1
     * @queryParam area_code string required 区域代码. Example: 330100
     * @queryParam project_cate_id integer 项目分类ID. Example: 1
     *
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": {
     *     "current_page": 1,
     *     "data": [
     *       {
     *         "id": 1,
     *         "name": "项目名称",
     *         "description": "项目描述",
     *         "price": "100.00",
     *         "duration": 60,
     *         "category": {
     *           "id": 1,
     *           "name": "分类名称"
     *         }
     *       }
     *     ],
     *     "total": 10,
     *     "per_page": 10
     *   }
     * }
     * @response 404 {
     *   "code": 404,
     *   "message": "技师不存在或未通过认证"
     * }
     */
    public function coachProjectList(Request $request)
    {
        $coachId = $request->input('coach_id');
        $areaCode = $request->input('area_code');
        $projectCateId = $request->input('project_cate_id');

        return $this->service->getCoachProjectList($coachId, $areaCode, $projectCateId);
    }
}
