package com.gree.mall.manager.controller.workerorder;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.websit.SettlementOrderDetail;
import com.gree.mall.manager.bean.websit.SettlementOrderLogicVO;
import com.gree.mall.manager.bean.workorder.ChangeAppointmentVO;
import com.gree.mall.manager.bean.workorder.ChangeWorkerVO;
import com.gree.mall.manager.bean.workorder.PgOrderProductDetailVO;
import com.gree.mall.manager.bean.workorder.WorkerOrderDetail;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.websit.SettlementOrderLogic;
import com.gree.mall.manager.logic.workorder.ChangeOrderLogic;
import com.gree.mall.manager.plus.entity.PgOrderProduct;
import com.gree.mall.manager.plus.entity.PgOrderProductDetail;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@Slf4j
@RestController
@Api(value = "工单变更", tags = {"工单变更"})
@RequestMapping(value = "/changeOrder", produces = "application/json; charset=utf-8")
public class ChangeOrderController {

    @Autowired
    private ChangeOrderLogic changeOrderLogic;


    @PostMapping("/changeAppointmentTime")
    @ApiOperation("修改预约时间")
    public ResponseHelper changeAppointmentTime(
            @RequestBody ChangeAppointmentVO changeAppointmentVO,
            HttpServletRequest request
    ) throws ParseException {
        for (String s : changeAppointmentVO.getIds()) {
            changeOrderLogic.changeAppointmentTime(s,changeAppointmentVO.getAppointmentTime(),changeAppointmentVO.getAppointmentEndTime(),changeAppointmentVO.getRemark());
        }

        return ResponseHelper.success();
    }


    @PostMapping("/changeWorker")
    @ApiOperation("选择多个师傅派工")
    public ResponseHelper changeWorker(
            @RequestBody ChangeWorkerVO changeWorkerVO,
            HttpServletRequest request
    ) throws ParseException {
        changeOrderLogic.changeWorker(changeWorkerVO.getIds(),changeWorkerVO.getWorkerIds(),changeWorkerVO.getWebsitId());
        return ResponseHelper.success();
    }



    @PostMapping("/getOrderProduct")
    @ApiOperation("完工明细")
    public ResponseHelper<List<PgOrderProductDetail>> getOrderProduct(
            @ApiParam(value = "工单号" , required = true) @RequestParam(required = true) String id,
            @ApiParam(value = "WAIT 待采集 WAIT_SAVE 待完善  OK 已采集" , required = false) @RequestParam(required = false) List<String> status,
            HttpServletRequest request
    ) throws ParseException {
        List<PgOrderProductDetail> pgOrderProducts = changeOrderLogic.getOrderProduct(id,status);
        return ResponseHelper.success(pgOrderProducts);
    }


    @PostMapping("/productDetail")
    @ApiOperation("采集详情")
    public ResponseHelper<PgOrderProductDetailVO> productDetail(
            @ApiParam(value = "采集详细id" , required = true) @RequestParam(required = true) String id,
            HttpServletRequest request
    ) throws ParseException {
        PgOrderProductDetailVO pgOrderProductDetail = changeOrderLogic.productDetail(id);
        return ResponseHelper.success(pgOrderProductDetail);
    }

    @PostMapping("/getOrderList")
    @ApiOperation(value = "获得电子支付")
    public ResponseHelper<List<WorkerOrderDetail>> getOrder(
            @ApiParam(required = false, value = "工单号") @RequestParam(required = false) String id

    ) throws Exception {
        List<WorkerOrderDetail> workerOrderDetail = changeOrderLogic.getOrderList(id);
        return ResponseHelper.success(workerOrderDetail);
    }




}
