package com.red.circle.other.app.inner.endpoint.activity;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.material.props.PropsActivityClientService;
import com.red.circle.other.inner.endpoint.activity.api.PropsActivityClientApi;
import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum;
import com.red.circle.other.inner.model.cmd.activity.SendActivityRewardCmd;
import com.red.circle.other.inner.model.cmd.material.PropsActivityRuleConfigParamCmd;
import com.red.circle.other.inner.model.cmd.material.PropsActivityRuleConfigQryCmd;
import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsGroup;
import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsRule;
import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsRuleDTO;
import com.red.circle.other.inner.model.dto.activity.props.ActivityResource;
import com.red.circle.other.inner.model.dto.material.PropsActivityRuleConfigDTO;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 道具活动配置服务.
 *
 * @author pengliang on 2023/6/5
 */
@Validated
@RestController
@RequestMapping(value = PropsActivityClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class PropsActivityClientEndpoint implements PropsActivityClientApi {

  private final PropsActivityClientService propsActivityClientService;

  @Override
  public ResultResponse<List<ActivityPropsRule>> listRule(SysOriginPlatformEnum sysOrigin,
      PropsActivityTypeEnum activityType) {
    return ResultResponse.success(propsActivityClientService.listRule(sysOrigin, activityType));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getRuleGtLevelCrystal(
      SysOriginPlatformEnum sysOrigin, Integer level) {
    return ResultResponse.success(
        propsActivityClientService.getRuleGtLevelCrystal(sysOrigin, level));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getRuleCrystalFirst(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        propsActivityClientService.getRuleCrystalFirst(sysOrigin));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getRuleLuckyBoxFirst(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        propsActivityClientService.getRuleLuckyBoxFirst(sysOrigin));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getRuleGameFruitBoxWinLast(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        propsActivityClientService.getRuleGameFruitBoxWinLast(sysOrigin));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getRuleGameFruitBoxRoundsLast(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(
        propsActivityClientService.getRuleGameFruitBoxRoundsLast(sysOrigin));
  }

  @Override
  public ResultResponse<ActivityPropsRule> getByRuleId(Long id) {
    return ResultResponse.success(propsActivityClientService.getByRuleId(id));
  }

  @Override
  public ResultResponse<List<ActivityResource>> listActivityResource(
      SysOriginPlatformEnum sysOrigin, PropsActivityTypeEnum activityType) {
    return ResultResponse.success(
        propsActivityClientService.listActivityResource(sysOrigin, activityType));
  }

  @Override
  public ResultResponse<List<Long>> listActivityResourceGroupIds(SysOriginPlatformEnum sysOrigin,
      PropsActivityTypeEnum activityType) {
    return ResultResponse.success(propsActivityClientService.listActivityResourceGroupIds(
        sysOrigin, activityType
    ));
  }

  @Override
  public ResultResponse<ActivityResource> getActivityResource(Long ruleId) {
    return ResultResponse.success(propsActivityClientService.getActivityResource(ruleId));
  }

  @Override
  public ResultResponse<Map<Long, ActivityPropsGroup>> mapActivityPropsGroup(String sysOrigin,
      Set<Long> groupIds) {
    return ResultResponse.success(propsActivityClientService.mapActivityPropsGroup(sysOrigin,
        groupIds));
  }

  @Override
  public ResultResponse<ActivityPropsGroup> getActivityPropsGroup(String sysOrigin, Long groupId) {
    return ResultResponse.success(propsActivityClientService.getActivityPropsGroup(sysOrigin,
        groupId));
  }

  @Override
  public ResultResponse<Void> sendActivityReward(SendActivityRewardCmd cmd) {
    propsActivityClientService.sendActivityReward(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Map<Long, ActivityPropsRuleDTO>> mapRuleConfigByIds(Collection<Long> ids) {
    return ResultResponse.success(propsActivityClientService.mapRuleConfigByIds(ids));
  }

  @Override
  public ResultResponse<PageResult<PropsActivityRuleConfigDTO>> pagePropsActivityRuleConfig(
      PropsActivityRuleConfigQryCmd query) {
    return ResultResponse.success(propsActivityClientService.pagePropsActivityRuleConfig(query));
  }


  @Override
  public ResultResponse<Void> propsActivityRuleConfigDeleteById(Long id) {
    propsActivityClientService.propsActivityRuleConfigDeleteById(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PropsActivityRuleConfigDTO> getPropsActivityRuleConfig(
      PropsActivityRuleConfigParamCmd param) {
    return ResultResponse.success(propsActivityClientService.getPropsActivityRuleConfig(param));
  }

  @Override
  public ResultResponse<Void> updatePropsActivityRuleConfigById(
      PropsActivityRuleConfigParamCmd param) {
    propsActivityClientService.updatePropsActivityRuleConfigById(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> savePropsActivityRuleConfig(PropsActivityRuleConfigParamCmd param) {
    propsActivityClientService.savePropsActivityRuleConfig(param);
    return ResultResponse.success();
  }
}
