package com.ycwl.basic.integration.questionnaire.client;

import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.questionnaire.dto.answer.ResponseDetailResponse;
import com.ycwl.basic.integration.questionnaire.dto.answer.SubmitAnswerRequest;
import com.ycwl.basic.integration.questionnaire.dto.questionnaire.CreateQuestionnaireRequest;
import com.ycwl.basic.integration.questionnaire.dto.questionnaire.QuestionnaireResponse;
import com.ycwl.basic.integration.questionnaire.dto.statistics.QuestionnaireStatistics;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "zt-questionnaire", contextId = "questionnaire", path = "/api")
public interface QuestionnaireClient {

    // ==================== 问卷管理接口 ====================
    
    /**
     * 创建问卷
     */
    @PostMapping("/questionnaires")
    CommonResponse<QuestionnaireResponse> createQuestionnaire(
            @RequestBody CreateQuestionnaireRequest request,
            @RequestHeader("X-User-ID") String userId
    );

    /**
     * 获取问卷详情
     */
    @GetMapping("/questionnaires/{id}")
    CommonResponse<QuestionnaireResponse> getQuestionnaire(@PathVariable("id") Long id);

    /**
     * 获取问卷列表
     */
    @GetMapping("/questionnaires")
    CommonResponse<PageResponse<QuestionnaireResponse>> getQuestionnaireList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String createdBy
    );

    /**
     * 更新问卷
     */
    @PutMapping("/questionnaires/{id}")
    CommonResponse<QuestionnaireResponse> updateQuestionnaire(
            @PathVariable("id") Long id,
            @RequestBody CreateQuestionnaireRequest request,
            @RequestHeader("X-User-ID") String userId
    );

    /**
     * 删除问卷
     */
    @DeleteMapping("/questionnaires/{id}")
    CommonResponse<Void> deleteQuestionnaire(
            @PathVariable("id") Long id,
            @RequestHeader("X-User-ID") String userId
    );

    /**
     * 发布问卷
     */
    @PostMapping("/questionnaires/{id}/publish")
    CommonResponse<QuestionnaireResponse> publishQuestionnaire(
            @PathVariable("id") Long id,
            @RequestHeader("X-User-ID") String userId
    );

    /**
     * 停止问卷
     */
    @PostMapping("/questionnaires/{id}/stop")
    CommonResponse<QuestionnaireResponse> stopQuestionnaire(
            @PathVariable("id") Long id,
            @RequestHeader("X-User-ID") String userId
    );

    // ==================== 答案提交接口 ====================

    /**
     * 提交问卷答案
     */
    @PostMapping("/questionnaires/submit")
    CommonResponse<ResponseDetailResponse> submitAnswer(@RequestBody SubmitAnswerRequest request);

    // ==================== 统计分析接口 ====================

    /**
     * 获取问卷统计
     */
    @GetMapping("/questionnaires/{id}/statistics")
    CommonResponse<QuestionnaireStatistics> getStatistics(@PathVariable("id") Long id);

    /**
     * 获取回答记录列表
     */
    @GetMapping("/responses")
    CommonResponse<PageResponse<ResponseDetailResponse>> getResponseList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Long questionnaireId,
            @RequestParam(required = false) String userId,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime
    );

    /**
     * 获取回答详情
     */
    @GetMapping("/responses/{id}")
    CommonResponse<ResponseDetailResponse> getResponseDetail(@PathVariable("id") Long id);


}