package com.red.circle.console.adapter.app.props;

import com.red.circle.common.business.core.ControllerRedisKeyConstant;
import com.red.circle.console.app.dto.clienobject.props.PropsCommodityStoreCO;
import com.red.circle.console.app.dto.cmd.app.props.PropsCommodityStoreAddOrUpdateCmd;
import com.red.circle.console.app.service.app.props.PropsStoreService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.material.PropsCommodityStoreQryCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 道具商店.
 *
 * @author pengshigang
 * @since 2022-4-13
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/props/store")
public class PropsStoreRestController extends BaseController {

  private final PropsStoreService propsStoreService;

  /**
   * 分页列表.
   */
  @GetMapping("/page")
  public PageResult<PropsCommodityStoreCO> pageQuery(PropsCommodityStoreQryCmd qryCmd) {
    return propsStoreService.pageQuery(qryCmd);
  }

  @Caching(evict = {
      @CacheEvict(value = ControllerRedisKeyConstant.PROPS_STORE, key = "#cmd.controllerCacheKeyGold()"),
      @CacheEvict(value = ControllerRedisKeyConstant.PROPS_STORE, key = "#cmd.controllerCacheKeyDiamond()"),
      @CacheEvict(value = ControllerRedisKeyConstant.PROPS_STORE, key = "#cmd.controllerCacheKeyFree()")
  })
  @OpsOperationReqLog(value = "添加或修改道具商店信息")
  @PostMapping("/add-or-update")
  public void addOrUpdate(@RequestBody @Validated PropsCommodityStoreAddOrUpdateCmd cmd) {
    propsStoreService.addOrUpdate(cmd);
  }

}
