package com.younike.system.service;

import com.younike.common.core.domain.AjaxResult;
import com.younike.hlpay.dto.OrderParam;
import com.younike.hlpay.dto.PaymentParam;
import com.younike.system.domain.*;
import com.younike.system.domain.vo.*;
import com.younike.system.domain.vo.MemberOrderDetailVo;
import com.younike.system.domain.vo.MemberOrderVo;
import com.younike.system.domain.vo.MerchantDashboardVO;
import com.younike.system.domain.vo.OrderVo;
import com.younike.system.param.OrderGroupParam;
import com.younike.system.param.OrderPublishParam;
import com.younike.system.param.OrderQueryParam;
import com.younike.system.param.OredrRefundParam;
import com.younike.wxpay.params.RefundNotificationParams;
import com.younike.wxpay.params.TransactionNotificationParams;
import com.younike.wxpay.responses.NotificationResponse;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单主Service接口
 *
 * @author elev
 * @date 2022-01-07
 */
public interface IOrderService {

    /**
     * 处理退款
     * @return
     */
    AjaxResult doRefund(OrderRefund orderRefund);
    /**
     * 后台订单列表
     * @param param
     * @return
     */
    List<OrderVo> orderList(OrderQueryParam param);
    /**
     * 查询订单主
     *
     * @param orderId 订单主主键
     * @return 订单主
     */
    Order selectOrderByOrderId(Long orderId);

    /**
     * 查询订单主列表
     *
     * @param order 订单主
     * @return 订单主集合
     */
    List<Order> selectOrderList(Order order);

    /**
     * 新增订单主
     *
     * @param order 订单主
     * @return 结果
     */
    int insertOrder(Order order);

    /**
     * 修改订单主
     *
     * @param order 订单主
     * @return 结果
     */
    int updateOrder(Order order);

    /**
     * 批量删除订单主
     *
     * @param orderIds 需要删除的订单主主键集合
     * @return 结果
     */
    int deleteOrderByOrderIds(Long[] orderIds);

    /**
     * 删除订单主信息
     *
     * @param orderId 订单主主键
     * @return 结果
     */
    int deleteOrderByOrderId(Long orderId);

    int updateOrderCustom(Order order);

    /**
     * 查询近days天的特定订单状态（orderStates）订单列表
     *
     * @param days 天数
     * @param orderStates 订单状态
     * @return 订单列表
     */
    List<OrderStat> listLastOrders(int days, String[] orderStates);

    /**
     * 统计近days天的特定订单状态（orderStates）的评分
     *
     * @param days 天数
     * @param orderStates 订单状态
     * @return 订单列表
     */
    List<GoodsServerDimension> statisticGoodsServerDimension(int days, String[] orderStates);

    /**
     * 查询会员端订单分页列表
     *
     * @param order
     * @return
     */
    List<MemberOrderVo> listMemberOrderByOrderState(Order order);

    void calculateShopAmount(Order order);

    /**
     * 会员下单
     *
     * @param param
     * @return
     */
    AjaxResult addOrder(OrderParam param);

    LocalDateTime recordAppointmentInfo(LocalDateTime start, BigDecimal cost, Long serverId, Integer composeFlag);

    /**
     * 查询会员订单详情
     *
     * @param orderId
     * @return
     */
    MemberOrderDetailVo getMemberOrderByOrderId(Long orderId);

    /**
     * 订单支付
     * @param param
     * @return
     */
    AjaxResult payment(PaymentParam param);

    /**
     * 取消订单
     * @param param
     * @return
     */
    AjaxResult cancal(OredrRefundParam param);

    /**
     * 申请平台介入（申请退款）
     * @param param
     * @return
     */
    AjaxResult applyForRefund(OredrRefundParam param);

    /**
     * 取消已预约记录
     * @param order 订单
     */
    void cancelBook(Order order);

    /**
     * 追加服务
     * @param param
     * @return
     */
    AjaxResult addServer(OrderParam param);


    /**
     * 确认完成
     * @param param
     * @return
     */
    AjaxResult affirm(OredrRefundParam param);

    /**
     * 取消申请平台介入
     * @param param
     * @return
     */
    AjaxResult cancelRefund(OrderParam param);

    /**
     * @param settleDate 结算截止时间
     */
    Map<Long, List<Order>> selectPreSettleOrders(Date settleDate);

    List<Order> selectPreSettleOrderList(Date settleDate);

    List<OrderPaymentVO> selectPreProfitSharingOrders(Date settleDate);

    boolean updateBatchById(List<Order> updated);

    MerchantDashboardVO dashboard(Long merchantId);

    AjaxResult payState(Long orderId);

    /**
     * 查询会员订单查询追加服务支付结果
     * @param orderId
     * @return
     */
    AjaxResult addServerCb(Long orderId);

    /**
     * 查询会员端未支付订单分页列表
     *
     * @param orderState
     * @return
     */
    List<Order> listMemberOrderOfPendingPayment(String orderState);

    /**
     * 更新超时未支付订单状态
     *
     * @param timeoutOrderList
     */
    void updateOrderState(List<Order> timeoutOrderList);

    /**
     * 查询今日订单数据
     *
     * @return
     */
    TodayOrderVO getTodayOrderData();

    /**
     * 查询本周Top5商家订单数据
     *
     * @return
     */
    List<MerchantOrderOfWeekVO> getTopFiveMerchantOrderData();

    /**
     * 查询近30天订单数据
     *
     * @return
     */
    List<OrderStatisticsVO> getOrderDataByMonth();

    /**
     * 发布需求：预约提交订单
     * @param param
     * @return
     */
    AjaxResult addPublishOrder(OrderPublishParam param);

    OrderVo selectPublishInfo(Long orderId);

    /**
     * 收取维修配件费
     * @param param
     * @return
     */
    AjaxResult maintenanceServer(OrderParam param);

    /**
     * 支付维修配件费
     * @param param
     * @return
     */
    AjaxResult addMaintenanceServer(OrderParam param);

    /**
     * 取消收取维修配件费
     * @param param
     * @return
     */
    AjaxResult cancelMaintenanceServer(OrderParam param);

    /**
     * 查询个体户结算订单信息
     *
     * @param settleStartDate
     * @param settleEndDate
     * @return
     */
    Map<Long, List<Order>> listPersonalMerchantSettleOrder(LocalDate settleStartDate, LocalDate settleEndDate);

    NotificationResponse paymentCb(TransactionNotificationParams data);

    NotificationResponse paymentAddServerCb(TransactionNotificationParams data);

    NotificationResponse paymentAddMaintanceCb(TransactionNotificationParams data);

    NotificationResponse bondCb(TransactionNotificationParams data);

    NotificationResponse refundCb(RefundNotificationParams data);
    /**
     * 根据服务id查询是否有订单非已取消与已退款状态
     *
     * @param goodsId
     * @return
     */
    List<Order> adminDeleteGoods(Long goodsId);

    /**
     * 根据服务人员id查询服务人员是否有未完成的订单
     *
     * @param serverIds
     * @return
     */
    List<Order> merchanServerUserId(Long[] serverIds);

    /**
     * 团购服务：预约提交订单
     *
     * @param param
     * @return
     */
    AjaxResult addGroupOrder(OrderGroupParam param);

    /**
     * 查询会员团购订单详情
     *
     * @param orderId
     * @return
     */
    MemberOrderDetailVo getMemberGroupOrderByOrderId(Long orderId);
}
