package com.gic.haoban.manage.web.controller.offline;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.web.qo.offline.PageOfflinePreQO;
import com.gic.haoban.manage.web.qo.offline.WriteOffOfflinePreQO;
import com.gic.haoban.manage.web.vo.offline.CountOfflinePreVO;
import com.gic.haoban.manage.web.vo.offline.OfflinePreInfoVO;
import com.gic.marketing.pro.api.dto.offline.CountOfflinePreDTO;
import com.gic.marketing.pro.api.dto.offline.OfflinePreInfoDTO;
import com.gic.marketing.pro.api.qdto.offline.PageOfflinePreQDTO;
import com.gic.marketing.pro.api.qdto.offline.WriteOffOfflinePreQDTO;
import com.gic.marketing.pro.api.service.offline.OfflinePreApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 好办小程序-线下预约
 */
@Controller
public class OfflinePreController {

    @Autowired
    private OfflinePreApiService offlinePreApiService;

    /**
     * 预约列表
     * @param qo 参数
     * @return 预约列表
     */
    @RequestMapping("/page-offline-pre")
    @ResponseBody
    public RestResponse<Page<OfflinePreInfoVO>> pageOfflinePre(@RequestBody PageOfflinePreQO qo){

        ServiceResponse<Page<OfflinePreInfoDTO>> offlinePreInfoDTO = offlinePreApiService.pageOfflinePre(JSONObject.parseObject(JSONObject.toJSONString(qo), PageOfflinePreQDTO.class));
        return JSONObject.parseObject(JSONObject.toJSONString(offlinePreInfoDTO, SerializerFeature.WriteMapNullValue), RestResponse.class);
    }

    /**
     * 获取预约详情
     * @param offlinePreId 预约ID
     * @param enterpriseId 企业ID
     * @return 预约详情
     */
    @RequestMapping("/get-offline-pre")
    @ResponseBody
    public RestResponse<OfflinePreInfoVO> getOfflinePre(Long offlinePreId, String enterpriseId){
        ServiceResponse<OfflinePreInfoDTO> offlinePreInfo = offlinePreApiService.getOfflinePre(offlinePreId, enterpriseId, null);
        return JSONObject.parseObject(JSONObject.toJSONString(offlinePreInfo, SerializerFeature.WriteMapNullValue), RestResponse.class);
    }

    /**
     * 核销预约单
     * @param qo 入参
     * @return
     */
    @RequestMapping("/write-off-offline-pre")
    @ResponseBody
    public RestResponse<Boolean> writeOffOfflinePre(@RequestBody WriteOffOfflinePreQO qo){
        ServiceResponse<Boolean> writeOffOfflinePre = offlinePreApiService.writeOffOfflinePre(JSONObject.parseObject(JSONObject.toJSONString(qo), WriteOffOfflinePreQDTO.class));
        return JSONObject.parseObject(JSONObject.toJSONString(writeOffOfflinePre, SerializerFeature.WriteMapNullValue), RestResponse.class);
    }

    /**
     * 预约统计
     * @param storeId 门店ID
     * @param enterpriseId 企业ID
     * @return 预约详情
     */
    @RequestMapping("/count-offline-pre")
    @ResponseBody
    public RestResponse<CountOfflinePreVO> countOfflinePre(String storeId, String enterpriseId){
        ServiceResponse<CountOfflinePreDTO> countOfflinePre = offlinePreApiService.countOfflinePre(storeId, enterpriseId);
        return JSONObject.parseObject(JSONObject.toJSONString(countOfflinePre, SerializerFeature.WriteMapNullValue), RestResponse.class);
    }


    /**
     * 校验是否核销
     * @param offlinePreId 预约ID
     * @param storeId 门店ID
     * @return 预约详情
     */
    @RequestMapping("/check-offline-pre-write-off")
    @ResponseBody
    public RestResponse<Void> checkOfflinePreWriteOff(Long offlinePreId, String storeId){
        ServiceResponse<Void> countOfflinePre = offlinePreApiService.checkOfflinePreWriteOff(offlinePreId, storeId);
        return JSONObject.parseObject(JSONObject.toJSONString(countOfflinePre, SerializerFeature.WriteMapNullValue), RestResponse.class);
    }
}
