<?php

namespace App\Http\Controllers\Client;

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

/**
 * @group 用户端
 *
 * 评论相关的API接口
 */
class CommentController extends Controller
{
    protected CommentService $service;

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

    /**
     * [评论管理] 发表评价
     *
     * 发表评价
     *
     * @authenticated
     *
     * @bodyParam coach_id int required 技师ID. Example: 1
     * @bodyParam content string required 评价内容. Example: 很棒的服务！
     * @bodyParam rating int required 评分. Example: 5
     *
     * @response {
     *   "code": 200,
     *   "message": "评价成功",
     *   "data": {
     *     "id": 1,
     *     "coach_id": 1,
     *     "content": "很棒的服务！",
     *     "rating": 5,
     *     "created_at": "2024-01-01 10:00:00"
     *   }
     * }
     */
    public function create(Request $request)
    {
        $coachId = $request->input('coach_id');
        $content = $request->input('content');
        $rating = $request->input('rating');

        return $this->service->createComment($coachId, $content, $rating);
    }

    /**
     * [评论管理] 评价列表
     *
     * 获取评价列表
     *
     * @authenticated
     *
     * @queryParam coach_id int required 技师ID. Example: 1
     *
     * @response {
     *   "code": 200,
     *   "message": "获取成功",
     *   "data": [
     *     {
     *       "id": 1,
     *       "coach_id": 1,
     *       "content": "很棒的服务！",
     *       "rating": 5,
     *       "created_at": "2024-01-01 10:00:00"
     *     }
     *   ]
     * }
     */
    public function list(Request $request)
    {
        $coachId = $request->input('coach_id');

        return $this->service->getCommentList($coachId);
    }
}
