package shop.alien.job.feign;

import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.AccountLogoutCompleteResultVo;

import java.util.Map;

@FeignClient(url = "${feign.alienStore.url}", name = "alien-store")
public interface AlienStoreFeign {

    @GetMapping("/websocket/sendMsgToClientByPhoneId")
    JSONObject sendMsgToClientByPhoneId(
            @RequestParam(value = "messageReceiverId") String messageReceiverId,
            @RequestParam(value = "webSocketVoStr") String webSocketVoStr);

    /**
     * 转账
     *
     * @param name
     * @param idCard
     * @param phone
     * @param money
     * @return
     */
    @GetMapping("/ali/pay")
    JSONObject aliPay(
            @RequestParam(value = "name") String name,
            @RequestParam(value = "idCard") String idCard,
            @RequestParam(value = "phone") String phone,
            @RequestParam(value = "money") String money
    );

    /**
     * 删除附近商家
     *
     * @param flag
     * @param content
     * @return
     */
    @GetMapping("/near/me/delMer")
    JSONObject delMer(
            @RequestParam(value = "flag") Boolean flag,
            @RequestParam(value = "content") String content
    );

    /**
     * 处理退款
     * @param outTradeNo 订单编号
     * @param refundAmount 退款金额
     * @param refundReason 退款原因
     * @return
     */
    @GetMapping("/ali/processRefund")
    public String processRefund(@RequestParam(value = "outTradeNo") String outTradeNo,
                                   @RequestParam(value = "refundAmount") String refundAmount,
                                   @RequestParam(value = "refundReason") String refundReason,
                                   @RequestParam(value = "partialRefundCode") String partialRefundCode);

    /**
     * 退款接口
     * @param params 退款参数（包含订单号、退款金额等）
     * @return 退款结果
     */
    @RequestMapping("payment/refunds")
    public R refunds(@RequestBody Map<String, String> params);

    /**
     * 预订未到店超时：retain_position_flag=1 时用 start_time+retention_duration，否则仅用 start_time；订单待使用则标记过期
     *
     * @return R.data 为本次更新的预约数量
     */
    @org.springframework.web.bind.annotation.PostMapping("/reservation/job/markTimeout")
    R<Integer> markReservationTimeoutByEndTime();

    /**
     * 到店提醒定时任务：订单待使用且距预定开始时间≤30分钟时发送短信提醒
     *
     * @return R.data 为本次发送短信条数
     */
    @org.springframework.web.bind.annotation.PostMapping("/reservation/job/sendArrivalReminder")
    R<Integer> sendArrivalReminder();

    /**
     * 重试退款定时任务：查询支付状态为退款中的订单并重新发起退款
     *
     * @return R.data 为本次退款成功的订单数
     */
    @org.springframework.web.bind.annotation.PostMapping("/reservation/job/retryRefundFailed")
    R<Integer> retryRefundFailed();

    /**
     * 特约商户进件：申请单号查询申请状态（转发微信 GET .../applyment_id/{applyment_id}）。
     * 需在配置中提供 {@code feign.alienStore.url} 指向 alien-store 根地址。
     *
     * @param applymentId 微信支付申请单号
     */
    @GetMapping("/payment/wechatPartner/v3/applyment4sub/applyment/applyment_id/{applyment_id}")
    R<Map<String, Object>> queryWechatPartnerApplymentState(@PathVariable("applyment_id") Long applymentId);

    /**
     * 用户补充申诉：提交待处理申诉至 AI 分析（getStoreCommentAppealSupplementAppealJob）
     */
    @PostMapping("/storeCommentAppealSupplement/job/submitAppealAnalyze")
    R<String> submitStoreCommentAppealSupplementAnalyze();

    /**
     * 用户补充申诉：轮询 AI 分析完成结果（getStoreCommentAppealSupplementCompletedResult）
     */
    @PostMapping("/storeCommentAppealSupplement/job/pollCompletedResult")
    R<String> pollStoreCommentAppealSupplementCompletedResult();

    /**
     * 执行到期的定时推送任务（sendType=2，status=审核通过，scheduledAt &lt;= now）
     *
     * @return R.data 为本次成功发送的任务数
     */
    @PostMapping("/commonPushTask/job/executeScheduled")
    R<Integer> executeScheduledPushTasks();

    /**
     * 同步已发送任务的厂商推送统计数据到 common_push_task_num
     *
     * @return R.data 为本次成功更新的任务数
     */
    @PostMapping("/commonPushTask/job/syncStatistics")
    R<Integer> syncPushTaskStatistics();

    /**
     * 注销冷静期到期处理（cancellationOfBusinessJob，满7天才会处理）
     */
    @PostMapping("/account/logout/job/completeCooling")
    R<AccountLogoutCompleteResultVo> completeAccountLogoutCooling();
}
