package com.kxs.store.biz.controller.kxsapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.common.security.annotation.Inner;
import com.kxs.store.api.dto.kxsapp.storeLimit.ForAmountWithdrawDTO;
import com.kxs.store.api.dto.kxsapp.storeLimit.WarehouseApplyDTO;
import com.kxs.store.api.model.KxsWarehouseCreditAmount;
import com.kxs.store.api.model.KxsWarehouseLimit;
import com.kxs.store.api.vo.kxsapp.storeLimit.WarehouseMachineApplyListVO;
import com.kxs.store.biz.service.KxsForAmountWithdrawService;
import com.kxs.store.biz.service.KxsWarehouseCreditAmountService;
import com.kxs.store.biz.service.KxsWarehouseLimitService;
import com.kxs.store.biz.service.KxsWarehouseMachineApplyService;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 仓库模块(StoreLimit)控制层
 *
 * @author 系统
 * @since 2024-01-10 18:14:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("storeLimit")
public class StoreLimitController {

    /**
     * 服务对象
     */
    private final KxsWarehouseLimitService kxsWarehouseLimitService;
    private final KxsWarehouseCreditAmountService kxsWarehouseCreditAmountService;
    private final KxsWarehouseMachineApplyService kxsWarehouseMachineApplyService;
    private final KxsForAmountWithdrawService kxsForAmountWithdrawService;



    /**
     * 申请补货-额度详情
     *
     * @return 申请补货-额度详情
     */
    @GetMapping("/warehouseAmount")
    public R warehouseAmount() {

        return R.ok(kxsWarehouseLimitService.warehouseAmount());
    }


    /**
     * 申请补货-分仓额度担保明细
     *
     * @param page 分页对象
     * @return 申请补货-分仓额度担保明细
     */
    @GetMapping("/creditAmountDetail")
    public R creditAmountDetail(@ParameterObject Page<KxsWarehouseCreditAmount> page) {

        return R.ok(kxsWarehouseCreditAmountService.page(page));
    }


    /**
     * 申请补货-申请补货提交
     *
     * @param param 提交对象
     * @return 申请补货-申请补货提交
     */
    @PostMapping("/warehouseApplySubmit")
    public R warehouseApplySubmit(@RequestBody WarehouseApplyDTO param) {

        return kxsWarehouseMachineApplyService.warehouseApplySubmit(param);
    }

    /**
     * 申请补货-申请记录
     *
     * @param page 分页对象
     * @return 申请补货-申请记录
     */
    @GetMapping("/getMachineApplyList")
    public R getMachineApplyList(@ParameterObject Page<WarehouseMachineApplyListVO> page) {

        return R.ok(kxsWarehouseMachineApplyService.getByPage(page));
    }


    /**
     * 申请补货-申请记录明细
     *
     * @param id 主键ID
     * @return 申请补货-申请记录明细
     */
    @GetMapping("/getMachineApplyDetail")
    public R getMachineApplyDetail(@RequestParam("id") Integer id) {

        return R.ok(kxsWarehouseMachineApplyService.getMachineApplyDetail(id));
    }


    /**
     * 申请补货-临额提现
     *
     * @param param 实体对象
     * @return 申请补货-减少临额
     */
    @PostMapping("/subFixedAmount")
    public R subFixedAmount(@RequestBody ForAmountWithdrawDTO param) {
        return R.ok(kxsForAmountWithdrawService.forAmountWithdraw(param));
    }


    /**
     * 分仓额度-临额增加
     *
     * @param param 实体对象
     * @return 临额增加
     */
    @Inner
    @PostMapping("/addForAmount")
    public R addForAmount(@RequestBody KxsWarehouseLimit param) {

        return R.ok(kxsWarehouseLimitService.addForAmount(param));
    }





}

