package com.muchinfo.mtp3century.controller;

import com.muchinfo.mtp3century.service.IForwardOrderService;
import com.muchinfo.mtp3century.service.IPresaleService;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3pojos.vo.presale.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/presale")
@Api(value = "预售管理API", description = "预售管理")
public class PresaleController {

    @Resource
    private IPresaleService iPresaleService;
    @Resource
    IForwardOrderService iForwardOrderService;

    @RequestMapping(method = RequestMethod.GET, value = "/query")
    @ApiOperation("预售管理--> 预售查询 --> 获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<PresaleQueryResult> query(PresaleQueryParam param, HttpServletRequest request) {
        return iPresaleService.query(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/view")
    @ApiOperation("预售管理--> 预售查询 --> 查看详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresaleQueryDetailResult> view(String applyid, HttpServletRequest request) {
        return iPresaleService.view(applyid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/viewPresaleLottery")
    @ApiOperation("预售管理--> 预售查询 --> 中签结果")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresalePresaleLotteryResult> viewPresaleLottery(Long goodsid, HttpServletRequest request) {
        return iPresaleService.viewPresaleLottery(goodsid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/viewfinsh")
    @ApiOperation("预售管理--> 预售查询 --> 配售结果")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresaleFinishResult> viewfinsh(Long goodsid, HttpServletRequest request) {
        return iPresaleService.viewfinsh(goodsid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/lottery")
    @ApiOperation("预售管理--> 预售查询 --> 摇号")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult lottery(Long goodsid, Integer lotteryqty, HttpServletRequest request) {
        return iPresaleService.lottery(goodsid, lotteryqty, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/complatesView")
    @ApiOperation("预售管理--> 预售查询 --> 完成")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresaleQueryResult> complatesView(Long goodsid, HttpServletRequest request) {
        return iPresaleService.complatesView(goodsid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/getAccountIds")
    @ApiOperation("预售管理--> 预售查询 --> 完成--> 配售信息新增初始化账号")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresaleFinishInitAddResult> getAccountIds(Long goodsid, HttpServletRequest request) {
        return iPresaleService.getAccountIds(goodsid, request);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/saveComplates")
    @ApiOperation("预售管理--> 预售查询 --> 完成--> 保存")
    @ApiResponse(code = 200, message = "成功", response = PresaleComplatesParam.class)
    public AjaxResult saveComplates(@RequestBody PresaleComplatesParam param, HttpServletRequest request) {
        return iPresaleService.saveComplates(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/queryApply")
    @ApiOperation("预售管理--> 预售申请 --> 获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<PresaleApplyResult> queryApply(PresaleApplyParam param, HttpServletRequest request) {
        return iPresaleService.queryApply(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/applyView")
    @ApiOperation("预售管理--> 预售申请 --> 详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<PresaleApplyResult> applyView(String applyid, HttpServletRequest request) {
        return iPresaleService.applyView(applyid, request);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/save")
    @ApiOperation("预售管理--> 预售申请 --> 新增")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult save(@RequestBody PresaleApplyAddParam param, HttpServletRequest request) {
        return iPresaleService.save(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/saveInit")
    @ApiOperation("预售管理--> 预售申请 --> 新增初始化市场信息")
    @ApiResponse(code = 200, message = "成功", response = PresaleApplyAddInitResult.class)
    public AjaxResult<PresaleApplyAddInitResult> saveInit(HttpServletRequest request) {
        return iPresaleService.saveInit(request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/queryForward")
    @ApiOperation("远期订单管理--> 订单申请 --> 获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<ForwardOrderApplyResult> queryForward(ForwardOrderApplyParam param, HttpServletRequest request) {
        return iForwardOrderService.queryForward(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/forwardView")
    @ApiOperation("远期订单管理--> 订单申请 --> 详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<ForwardOrderApplyResult> forwardView(String applyid, HttpServletRequest request) {
        return iForwardOrderService.forwardView(applyid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/forwardAddInit")
    @ApiOperation("远期订单管理--> 订单申请 --> 新增--> 初始化市场、商品信息（确定商品后展示其余信息）")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<ForwardAddMarketAndGoods> forwardAddInit(Long marketid, Long goodid, HttpServletRequest request) {
        return iForwardOrderService.forwardAddInit(marketid, goodid, request);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/forwardAdd")
    @ApiOperation("远期订单管理--> 订单申请 --> 新增")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult forwardAdd(@RequestBody ForwardAddParam param, HttpServletRequest request) {
        return iForwardOrderService.forwardAdd(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/queryCancelApply")
    @ApiOperation("远期订单管理--> 注销申请 --> 获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<ForwardCancelApplyResult> queryCancelApply(ForwardCancelApplyParam param, HttpServletRequest request) {
        return iForwardOrderService.queryCancelApply(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/cancelApplyView")
    @ApiOperation("远期订单管理--> 注销申请 --> 详情")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public AjaxResult<ForwardCancelApplyResult> cancelApplyView(Long cancelid, HttpServletRequest request) {
        return iForwardOrderService.cancelApplyView(cancelid, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/cancelApplyAddInit")
    @ApiOperation("远期订单管理--> 注销申请 --> 新增 --> 获取市场列表信息")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public AjaxResult<ForwardCancelApplyInit> cancelApplyAddInit(Long accountid, HttpServletRequest request) {
        return iForwardOrderService.cancelApplyAddInit(accountid, request);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/cancelApplyAdd")
    @ApiOperation("远期订单管理--> 注销申请 --> 新增")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult cancelApplyAdd(@RequestBody ForwardCancelAddParam param, HttpServletRequest request) {
        return iForwardOrderService.cancelApplyAdd(param, request);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/queryOrder")
    @ApiOperation("远期订单管理--> 订单查询 --> 获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<ForwardOrderQueryResult> queryOrder(ForwardOrderQueryParam param, HttpServletRequest request) {
        return iForwardOrderService.queryOrder(param, request);
    }
}
