package com.ylx.order.controller;

import com.ylx.common.core.domain.R;
import com.ylx.order.domain.dto.RegulationConfigDTO;
import com.ylx.order.service.RegulationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order/regulation")
@Api(tags = {"订单规则配置模块"})
@Slf4j
public class RegulationController {

    @Resource
    private RegulationService regulationService;

    /**
     * 保存订单流转与退款规则配置
     * @param dto
     * @return R<?>
     */
    @ApiOperation("保存订单流转与退款规则配置")
    @PostMapping("/save")
    public R<?> saveConfig(@RequestBody @Validated RegulationConfigDTO dto) {
        this.regulationService.saveFullConfig(dto);
        return R.ok();
    }

    /**
     * 获取当前配置（用于回显）
     *
     * @return R<RegulationConfigDTO>
     */
    @ApiOperation("获取当前配置（用于回显）")
    @GetMapping("/get")
    public R<RegulationConfigDTO> getConfig() {
        RegulationConfigDTO config = this.regulationService.getFullConfig();
        return R.ok(config);
    }

}
