package com.dayou.controller;

import com.dayou.annotation.IgnoreAuth;
import com.dayou.common.RestResponse;
import com.dayou.configuration.DfsConfig;
import com.dayou.dto.NameUrlDTO;
import com.dayou.dto.OrderProductionsBag;
import com.dayou.dto.OrderReportDTO;
import com.dayou.dto.ReportDTO;
import com.dayou.service.*;
import com.dayou.vo.ProdValidateVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类说明：业务产品
 *
 * @author: wucl
 * @since: 2023/12/14
 * created with IntelliJ IDEA.
 */
@RestController
@RequestMapping("businessProduction")
@Slf4j
public class BusinessProductionController{

    @Autowired
    private IMajorProductionService majorProductionService;

    @Autowired
    private IBusinessProductionService businessProductionService;

    @Autowired
    private IPersonalProductionService personalProductionService;

    @Autowired
    private IAssetsProductionService assetsProductionService;

    @Autowired
    private IAssetsService assetsService;


    @Autowired
    private IPersonalService personalService;

    /**
     * 大中型产品包
     */
    @GetMapping("/bag/major/{id}")
    public RestResponse<OrderProductionsBag> productionBag(@PathVariable("id") Long id){
        OrderProductionsBag bag = majorProductionService.productionBag(id);
        return RestResponse.data(bag);
    }

    /**
     * 个贷产品包
     */
    @GetMapping("/bag/personal/{id}")
    public RestResponse<OrderProductionsBag> productionPersonalBag(@PathVariable("id") Long id){
        OrderProductionsBag bag = personalProductionService.productionBag(id);
        return RestResponse.data(bag);
    }

    /**
     * 大中型列表
     */
    @GetMapping("/major/{orderFundId}")
    public RestResponse<List<ReportDTO>> getProductionByOrderFundId(@PathVariable("orderFundId") Long orderFundId){
        List<ReportDTO> productions = majorProductionService.getProductionByOrderFundId(orderFundId);
        return RestResponse.data(productions);
    }

    /**
     * 多个订单报告列表
     * @param claimOrders
     * @return
     */
    @PostMapping("/report/major")
    public RestResponse<List<OrderReportDTO>> getOrderReport(@RequestBody List<OrderReportDTO> claimOrders){
        List<OrderReportDTO> list = majorProductionService.getOrderReport(claimOrders);
        return RestResponse.data(list);
    }


    /**
     * 实收款认领到 产品
     * @return
     */
    @PostMapping("/allotRealAmount/major")
    public RestResponse<Boolean> allotRealAmount(@RequestBody List<OrderReportDTO> claimOrders){
        Boolean ret = majorProductionService.allotRealAmount(claimOrders);
        return RestResponse.data(ret);
    }

    /**
     * 实收款认领到 订单
     * @return
     */
    @PostMapping("/allotRealAmountOrder/major")
    public RestResponse<Boolean> allotRealAmountToOrder(@RequestBody List<OrderReportDTO> claimOrders){
        Boolean ret = majorProductionService.allotRealAmountToOrder(claimOrders);
        return RestResponse.data(ret);
    }

    /**
     * 实收款分配到产品
     * @return
     */
    @PostMapping("/major/allot")
    public RestResponse<Boolean> allotRealAmountToProduction(@RequestBody OrderReportDTO orderReportDTO){
        Boolean ret = majorProductionService.allotRealAmountToProduction(orderReportDTO);
        return RestResponse.data(ret);
    }

    /**
     * 产品加盖公章
     * @param nameUrlDTO
     * @return
     */
    @PostMapping("/doStamp")
    public RestResponse<Boolean> addPublicStamp(@RequestBody NameUrlDTO nameUrlDTO){
        Boolean ret = businessProductionService.addPublicStamp(nameUrlDTO.getUrl());
        return RestResponse.data(ret);
    }

    /**
     * 个贷实收款选择认领
     * @return
     */
    @PostMapping("/allotRealAmount/personal")
    public RestResponse<Boolean> personalAllotRealAmount(@RequestBody List<OrderReportDTO> claimOrders){
        Boolean ret = personalService.personalAllotRealAmount(claimOrders);
        return RestResponse.data(ret);
    }

    /**
     * 产品验证接口
     */
    @IgnoreAuth
    @GetMapping("/validate/{businessType}/{businessId}")
    public RestResponse<ProdValidateVO> validateProd(@PathVariable("businessType") String businessType, @PathVariable("businessId") Long businessId){
        ProdValidateVO validateVO = businessProductionService.validateProd(businessType,businessId);
        return RestResponse.data(validateVO);
    }

    /**
     * 资产认领实收款到 订单
     * @param claimOrders 认领信息
     * @return Boolean
     */
    @PostMapping("/assets/doAllotRealAmountToOrder")
    public RestResponse<Boolean> doAllotRealAmountToOrder(@RequestBody List<OrderReportDTO> claimOrders) {
        return RestResponse.data(assetsService.doAllotRealAmountToOrder(claimOrders));
    }

    /**
     * 资产认领实收款到 产品
     * @param claimOrders 认领信息
     * @return Boolean
     */
    @PostMapping("/assets/doAllotRealAmountToProd")
    public RestResponse<Boolean> doAllotRealAmountToProd(@RequestBody List<OrderReportDTO> claimOrders) {
        return RestResponse.data(assetsProductionService.doAllotRealAmountToProd(claimOrders));
    }

    /**
     * 大中型、资产、个贷产品通用出入库接口
     * @param productionNo
     * @return
     */
    @PostMapping("/wareHouse")
    public RestResponse<Boolean> inOutWareHouse(@RequestParam("productionNo") String productionNo){
        Boolean ret = businessProductionService.inOutWareHouse(productionNo);
        return RestResponse.data(ret);
    }
}
