package com.fzm.mall.server.admin.order.controller;


import com.fzm.mall.server.admin.annotation.AdminLog;
import com.fzm.mall.server.admin.enums.log.OperateModuleEnum;
import com.fzm.mall.server.admin.enums.log.OperateTypeEnum;
import com.fzm.mall.server.admin.order.entity.dto.ConfigDTO;
import com.fzm.mall.server.admin.order.entity.dto.ConfigUpdateDTO;
import com.fzm.mall.server.admin.order.service.IConfigService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 订单中心-订单设置 前端控制器
 * </p>
 *
 * @author wulixian
 * @since 2021-03-17
 */
@Api(tags = "订单中心")
@RestController
@RequestMapping("/config/configPermission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ConfigController {

    private final IConfigService configService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "订单中心-订单设置-编辑")
    @ApiOperationSupport(order = 2)
    @AdminLog(description = "订单中心-订单设置-编辑", module = OperateModuleEnum.ORDER_CENTER, opType = OperateTypeEnum.UPDATE)
    @PutMapping("/update")
    public ResponseVO update(@RequestBody @Valid ConfigUpdateDTO configUpdateDTO) {

        configService.update(configUpdateDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "订单中心-订单设置-主键查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/{id}")
    public ResponseVO<ConfigDTO> read(
            @ApiParam(value = "id", required = true) @PathVariable(value = "id") String id) {
        ConfigDTO result = configService.read(id);
        return resFac.getSuccessResponseWithData(result);
    }

    @ApiOperation(value = "订单中心-订单设置-列表查询")
    @ApiOperationSupport(order = 5)
    @GetMapping("/list")
    public ResponseVO list() {
        List<ConfigDTO> result = configService.listAll();
        return resFac.getSuccessResponseWithData(result);
    }
}
