package com.red.circle.other.adapter.app.material;

import com.red.circle.common.business.core.ControllerRedisKeyConstant;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.material.PropsNobleVipStoreCO;
import com.red.circle.other.app.dto.clientobject.material.PropsStoreCommodityInfoCO;
import com.red.circle.other.app.dto.cmd.material.PropsGiveAwayCmd;
import com.red.circle.other.app.dto.cmd.material.PropsNobleVipQryCmd;
import com.red.circle.other.app.dto.cmd.material.PropsPurchasingCmd;
import com.red.circle.other.app.dto.cmd.material.PropsStoreBackpackTypeQryCmd;
import com.red.circle.other.app.dto.cmd.material.PropsStoreTypeQryCmd;
import com.red.circle.other.app.dto.cmd.material.SwitchUsePropsCmd;
import com.red.circle.other.app.service.material.PropsStoreService;
import com.red.circle.other.inner.model.dto.material.props.UserBackpackProps;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.MediaType;
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 pengliang on 2023/9/19
 * @eo.api-type http
 * @eo.groupName 道具服务.道具商店
 * @eo.path /material/props-store
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/material/props-store", produces = MediaType.APPLICATION_JSON_VALUE)
public class PropsStoreRestController extends BaseController {

  private final PropsStoreService propsStoreService;

  /**
   * 道具列表.
   *
   * @eo.name 道具列表.
   * @eo.url /list
   * @eo.method get
   * @eo.request-type formdata
   */
  @Cacheable(value = ControllerRedisKeyConstant.PROPS_STORE, key = "#cmd.controllerCacheKey()", unless = "#result == null")
  @GetMapping("/list")
  public List<PropsStoreCommodityInfoCO> listStoreTheme(@Validated PropsStoreTypeQryCmd cmd) {
    return propsStoreService.listStore(cmd);
  }

  /**
   * 贵族列表.
   *
   * @eo.name 贵族列表.
   * @eo.url /noble-vip
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/noble-vip")
  public List<PropsNobleVipStoreCO> listNobleVip(@Validated PropsNobleVipQryCmd cmd) {
    return propsStoreService.listNobleVip(cmd);
  }

  /**
   * 道具商店购买.
   *
   * @eo.name 道具商店购买.
   * @eo.url /purchasing
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/purchasing")
  public BigDecimal purchasingV2(@RequestBody @Validated PropsPurchasingCmd cmd) {
    return propsStoreService.purchasing(cmd);
  }

  /**
   * 赠送道具.
   *
   * @eo.name 赠送道具.
   * @eo.url /give-away
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/give-away")
  public BigDecimal giveAway(@RequestBody @Validated PropsPurchasingCmd cmd) {
    return propsStoreService.giveAway(cmd);
  }

  /**
   * 背包内赠送道具.
   *
   * @eo.name 背包内赠送道具.
   * @eo.url /give-away/backpack
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/give-away/backpack")
  public void giveAwayInBackpack(@RequestBody @Validated PropsGiveAwayCmd cmd) {
    propsStoreService.giveAwayInBackpack(cmd);
  }

  /**
   * 用户道具背包.
   *
   * @eo.name 用户道具背包.
   * @eo.url /backpack
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/backpack")
  public List<UserBackpackProps> backpack(@Validated PropsStoreBackpackTypeQryCmd cmd) {
    return propsStoreService.listUserBackpack(cmd);
  }

  /**
   * 切换我的道具.
   *
   * @eo.name 切换我的道具.
   * @eo.url /switch-use
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/switch-use")
  public void switchUse(@RequestBody @Validated SwitchUsePropsCmd cmd) {
    propsStoreService.switchUse(cmd);
  }

  /**
   * 购买房间锁.
   *
   * @eo.name 购买房间锁.
   * @eo.url /purchasing/room-lock
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/purchasing/room-lock")
  public BigDecimal purchasingRoomLock(AppExtCommand cmd) {
    return propsStoreService.purchasingRoomLock(cmd);
  }

  /**
   * 获取房间锁过期时间.
   *
   * @eo.name 获取房间锁过期时间.
   * @eo.url /room-lock/expired-time
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/room-lock/expired-time")
  public Timestamp getRoomLockExpiredTime(AppExtCommand cmd) {
    return propsStoreService.getRoomLockExpiredTime(cmd);
  }

  /**
   * 购买隐身访问道具.
   *
   * @eo.name 购买隐身访问道具.
   * @eo.url /purchasing/stealth-browse
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/purchasing/stealth-browse")
  public BigDecimal purchasingStealthBrowse(AppExtCommand cmd) {
    return propsStoreService.purchasingStealthBrowse(cmd);
  }

  /**
   * 获取隐身访问道具过期时间.
   *
   * @eo.name 获取隐身访问道具过期时间.
   * @eo.url /stealth-browse/expired-time
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/stealth-browse/expired-time")
  public Timestamp getStealthBrowseExpiredTime(AppExtCommand cmd) {
    return propsStoreService.getStealthBrowseExpiredTime(cmd);
  }

}
