package com.gree.mall.manager.controller.material.manage;

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.material.manage.WebsitPartsConfigBean;
import com.gree.mall.manager.bean.material.manage.WebsitPartsConfigVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.material.manage.WebsitPartsConfigLogic;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(value = "配件配置", tags ={"配件配置"} )
@RequestMapping(value = "/parts/refund/config", produces = "application/json; charset=utf-8")
public class WebsitPartsConfigController {

    @Resource
    WebsitPartsConfigLogic websitPartsConfigLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "配件返还配置-列表")
    public ResponseHelper<IPage<WebsitPartsConfigVO>> page(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<WebsitPartsConfigVO> page = websitPartsConfigLogic.page(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<WebsitPartsConfigVO>() {});
    }

    @PostMapping("/get/default")
    @ApiOperation(value = "配件返还配置-获取默认数据")
    public ResponseHelper<WebsitPartsConfigBean> getDefault() {
        WebsitPartsConfigBean bean = websitPartsConfigLogic.getDefault();
        return ResponseHelper.success(bean);
    }

    @PostMapping("/detail")
    @ApiOperation("配件返还配置详情")
    public ResponseHelper<WebsitPartsConfigBean> detail(
            @ApiParam(value = "id", required = true) @RequestParam String id
    ) throws Exception {
        return ResponseHelper.success(websitPartsConfigLogic.detail(id));
    }

    @PostMapping("/add")
    @ApiOperation("配件返还配置添加")
    public ResponseHelper add(@RequestBody WebsitPartsConfigBean bean) throws Exception {

        websitPartsConfigLogic.add(bean);

        return ResponseHelper.success();
    }

    @PostMapping("/edit")
    @ApiOperation("配件返还配置编辑")
    public ResponseHelper edit(@RequestBody WebsitPartsConfigBean bean) throws Exception {

        websitPartsConfigLogic.edit(bean);

        return ResponseHelper.success();
    }

    @PostMapping("/batch/del")
    @ApiOperation("配件返还配置批量删除")
    public ResponseHelper batchDel(@RequestBody List<String> ids) throws Exception {

        websitPartsConfigLogic.batchDel(ids);

        return ResponseHelper.success();
    }
}
