package com.yueqian.xingyun.sc.controller.sale;

import com.lframework.starter.web.core.controller.DefaultBaseController;
import com.lframework.starter.web.core.components.resp.InvokeResult;
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
import com.yueqian.xingyun.sc.bo.sale.config.GetSaleConfigBo;
import com.yueqian.xingyun.sc.entity.SaleConfig;
import com.yueqian.xingyun.sc.service.sale.SaleConfigService;
import com.yueqian.xingyun.sc.vo.sale.config.UpdateSaleConfigVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 销售参数设置
 *
 * @author zmj
 */
@Tag(name = "销售参数设置")
@Validated
@RestController
@RequestMapping("/sale/config")
public class SaleConfigController extends DefaultBaseController {

    @Autowired
    private SaleConfigService saleConfigService;

    /**
     * 查询详情
     */
    @Operation(summary = "查询详情")
    @GetMapping
    public InvokeResult<GetSaleConfigBo> get() {

        SaleConfig config = saleConfigService.get();
        GetSaleConfigBo result = new GetSaleConfigBo(config);

        return InvokeResultBuilder.success(result);
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @PutMapping
    public InvokeResult<Void> update(@Valid UpdateSaleConfigVo vo) {

        saleConfigService.update(vo);

        saleConfigService.cleanCacheByKey(null);

        return InvokeResultBuilder.success();
    }
}
