package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.infra.api.SettingServiceI;
import com.xunhong.erp.turbo.api.infra.dto.cmd.SettingUpdateCmd;
import com.xunhong.erp.turbo.api.infra.dto.qry.SettingShowQry;
import com.xunhong.erp.turbo.api.infra.dto.vo.SettingVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "Setting", description = "系统设置管理")
@RestController("operationSettingController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class SettingController {

	@DubboReference(version = "1.0.0")
	private final SettingServiceI settingService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_STORE_SETTING_VIEW})
	@GetMapping("showSetting")
	@Operation(summary = "系统设置详情", method = "GET")
	public SingleResponse<SettingVO> showSetting(@ModelAttribute @Validated SettingShowQry settingShowQry) {
		return SingleResponse.of(settingService.show(settingShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_STORE_SETTING_UPDATE})
	@RequestMapping(value = "updateSetting", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "系统设置更新", method = "PATCH")
	public SingleResponse<SettingVO> updateSetting(@RequestBody @Validated SettingUpdateCmd settingUpdateCmd) {
		return SingleResponse.of(settingService.update(settingUpdateCmd));
	}
}
