/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.finance.service;

import org.springblade.core.tool.support.Kv;
import org.springblade.modules.api.request.OrderCommonSaveRequest;
import org.springblade.modules.api.request.OrderConsignRandomRequest;
import org.springblade.modules.api.request.OrderConsignSaveRequest;
import org.springblade.modules.api.response.ConsignResponse;
import org.springblade.modules.finance.entity.Order;
import org.springblade.modules.api.request.OrderTakeRequest;
import org.springblade.modules.finance.vo.OrderVO;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.shopping.entity.Consign;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.entity.UserApp;

/**
 * 订单表 服务类
 *
 * @author BladeX
 * @since 2022-02-13
 */
public interface IOrderService extends IService<Order> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param order
	 * @return
	 */
	IPage<OrderVO> selectOrderPage(IPage<OrderVO> page, OrderVO order);


	/**
	 * 生成普通订单
	 * @param request 请求参数
	 * @param tenantId 租户号
	 * @return 订单号
	 */
	String commonOrderInsert(OrderCommonSaveRequest request, String tenantId);

	/**
	 *
	 * 支付回调调用成功的方法
	 *
	 * 订单支付成功
	 * 1.订单表
	 * 	 订单状态pay_flag： 待付款 -> 待发货
	 * @param queryOrder 订单
	 * @return boolean
	 */
	boolean payCommonSuccess(Order queryOrder, String payCode);


	/**
	 * 进货订单
	 * 1.授权完成修改状态
	 * 2.添加支付人寄售数据
	 * 2.如果是抢购而且是寄售类型consignType为寄售则添加寄售数据
	 * @return boolean
	 */
	boolean payConsignSuccess(Order order);

	/**
	 * 订单完成
	 * 1.订单表
	 * 	用户确认收货、或者商家确认收货
	 * 2.寄售订单表
	 *
	 * @param orderId 订单ID
	 * @return boolean
	 */
	boolean orderEnd(Long orderId, Long userId);

	/**
	 * 提货
	 * 订单状态变为待收货
	 * @param request 用户ID
	 * @return
	 */
	boolean consignSelfTake(OrderTakeRequest request);


	/**
	 * 寄售抢购
	 * @param request 请求参数
	 * @param tenantId 租户号
	 * @return Response
	 */
	String consignOrderInsert(OrderConsignRandomRequest request, UserApp userApp,String tenantId);


	/**
	 * 是否可抢
	 *
	 * @param query 用户ID
	 * @param consignConfigId 场次ID
	 * @return Kv
	 */
	ConsignResponse consignGrant(UserApp query, Long consignConfigId, String orderNo);
}
