package com.zfire.mall.manager.controller.config;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.bean.config.*;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.common.CommonLogic;
import com.zfire.mall.manager.logic.config.TradeConfigLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author qinrongjun
 * @description
 * @date 2023/7/26 13:44 星期三
 */

@RequiredArgsConstructor
@Validated
@RestController
@Api(value = "行业配置", tags = "行业配置")
@RequestMapping(value = "config/tradeConfig")
public class TradeConfigController {
    private final TradeConfigLogic tradeConfigLogic;
    private final CommonLogic commonLogic;

    @PostMapping("list")
    @ApiOperation(value = "列表")
    public ResponseHelper<IPage<TradeConfigListVO>> list(@RequestBody @Valid TradeConfigListParam param) {
        return ResponseHelper.success(tradeConfigLogic.list(param));
    }

    @PostMapping("listLevel")
    @ApiOperation(value = "列表级别")
    public ResponseHelper<List<TradeConfigListLevelVO>> listLevel(
            @RequestParam(required = false)
            @ApiParam("搜索关键字") String keyword) {
        return ResponseHelper.success(tradeConfigLogic.listLevel(keyword));
    }

    @PostMapping("edit")
    @ApiOperation(value = "编辑")
    public ResponseHelper edit(@RequestBody @Valid TradeConfigEditParam param) {
        return ResponseHelper.toResult(tradeConfigLogic.edit(param, commonLogic.getAdminUser()));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseHelper add(@RequestBody @Valid TradeConfigAddParam param) {
        return ResponseHelper.toResult(tradeConfigLogic.add(param, commonLogic.getAdminUser()));
    }

    @PostMapping("del")
    @ApiOperation(value = "删除")
    public ResponseHelper del(
            @ApiParam("行业配置id")
            @NotBlank(message = "id不能为空")
            @Length(max = 64, message = "id最大长度为64")
            @RequestParam String id) {
        return ResponseHelper.toResult(tradeConfigLogic.del(id));
    }
}
