package com.cyksj.web.controller.manage.wholesale;

import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.model.entity.WebWholesaleOrderDon;
import com.cyksj.model.views.WebWholesaleCodeDetailView;
import com.cyksj.model.views.WebWholesaleOrderView;
import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.SearchResult;
import com.ejlchina.searcher.util.MapUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 兑换码管理
 * 项目名: yhlxj2
 * 文件名: WholesaleCodeController
 * 创建者: JavaZou
 * 创建时间:2025/6/4 16:31
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/wholesale/code")
public class WholesaleCodeController {
	private final BeanSearcher beanSearcher;

	private final HttpServletRequest request;

	/**
	 * 兑换码 明细
	 */
	@GetMapping("/get/detail")
	public Result<SearchResult<WebWholesaleCodeDetailView>> getCodeDetail() {
		SearchResult<WebWholesaleCodeDetailView> search = beanSearcher.search(WebWholesaleCodeDetailView.class, MapUtils.flatBuilder(request.getParameterMap())
				.field(WebWholesaleCodeDetailView::getStatus, WebWholesaleOrderDon.Status.complete.name())
				.build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
	}

	/**
	 * 兑换码订单列表
	 */
	@GetMapping("/get/order")
	public Result<SearchResult<WebWholesaleOrderView>> getOrders() {
		SearchResult<WebWholesaleOrderView> search = beanSearcher.search(WebWholesaleOrderView.class, MapUtils.flatBuilder(request.getParameterMap())
				.field(WebWholesaleOrderView::getStatus, WebWholesaleOrderDon.Status.complete.name())
				.build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
	}

}
