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 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("/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);
    }
}
