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

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.sys.SysActivityConfigClientService;
import com.red.circle.other.inner.endpoint.sys.api.SysActivityConfigClientApi;
import com.red.circle.other.inner.model.cmd.activity.lottery.ActivityLotteryTurntableCache;
import com.red.circle.other.inner.model.cmd.sys.ActivityConfigBackQryCmd;
import com.red.circle.other.inner.model.cmd.sys.AddLotteryTurntableCmd;
import com.red.circle.other.inner.model.dto.sys.ActivityConfigDTO;
import com.red.circle.other.inner.model.dto.sys.ActivityConfigRewardsInfoDTO;
import com.red.circle.other.inner.model.dto.sys.ActivityTemplateDTO;
import com.red.circle.other.inner.model.dto.sys.ActivityTemplateValueDTO;
import com.red.circle.other.inner.model.dto.sys.SysActivityCountDTO;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 活动配置
 *
 * @author zongpubin on 2023/10/10
 */
@Validated
@RestController
@RequestMapping(value = SysActivityConfigClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class SysActivityConfigClientEndpoint implements SysActivityConfigClientApi {

  private final SysActivityConfigClientService sysActivityConfigClientService;

  @Override
  public ResultResponse<List<ActivityTemplateDTO>> listActivityTemplate(Long id, Long lastId,
      Integer pageSize) {
    return ResultResponse.success(
        sysActivityConfigClientService.listActivityTemplate(id, lastId, pageSize));
  }

  @Override
  public ResultResponse<ActivityTemplateDTO> getTemplateById(Long id) {
    return ResultResponse.success(sysActivityConfigClientService.getTemplateById(id));
  }

  @Override
  public ResultResponse<List<ActivityTemplateValueDTO>> listValues() {
    return ResultResponse.success(sysActivityConfigClientService.listValues());
  }

  @Override
  public ResultResponse<Void> saveTemplate(ActivityTemplateDTO param) {
    sysActivityConfigClientService.saveTemplate(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateTemplateById(ActivityTemplateDTO param) {
    sysActivityConfigClientService.updateTemplateById(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateTemplateName(Long id, String name, Long updateUser) {
    sysActivityConfigClientService.updateTemplateName(id, name, updateUser);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> saveActivityConf(ActivityConfigDTO param) {
    sysActivityConfigClientService.saveActivityConf(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<ActivityConfigDTO> getActivityConfigById(Long id) {
    return ResultResponse.success(sysActivityConfigClientService.getActivityConfigById(id));
  }

  @Override
  public ResultResponse<Void> updateSelectiveById(ActivityConfigDTO param) {
    sysActivityConfigClientService.updateSelectiveById(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<ActivityConfigDTO>> listActivityConf(ActivityConfigBackQryCmd query) {
    return ResultResponse.success(sysActivityConfigClientService.listActivityConf(query));
  }

  @Override
  public ResultResponse<ActivityConfigDTO> effectiveActivityConf(ActivityConfigBackQryCmd query) {
    return ResultResponse.success(sysActivityConfigClientService.getEffectiveActivityConf(query));
  }

  @Override
  public ResultResponse<ActivityConfigDTO> effectiveActivityByTemplate(Long templateId, String activityType) {
    return ResultResponse.success(sysActivityConfigClientService.getShowcaseActivityConf(templateId, activityType));
  }

  @Override
  public ResultResponse<Map<Long, ActivityTemplateValueDTO>> mapByIds(Set<Long> collect) {
    return ResultResponse.success(sysActivityConfigClientService.mapByIds(collect));
  }

  @Override
  public ResultResponse<List<SysActivityCountDTO>> listRank(Long activityId, String type,
      Integer size) {
    return ResultResponse.success(sysActivityConfigClientService.listRank(activityId, type, size));
  }

  @Override
  public ResultResponse<Void> updateRewards(
      ActivityConfigRewardsInfoDTO activityConfigRewardsInfoDTO) {
    sysActivityConfigClientService.updateRewards(activityConfigRewardsInfoDTO);
    return ResultResponse.success();
  }

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

  @Override
  public ResultResponse<Void> updateButOneRewardsStatusTrue(Long id, Long rewardId) {
    sysActivityConfigClientService.updateButOneRewardsStatusTrue(id, rewardId);
    return ResultResponse.success();

  }

  @Override
  public ResultResponse<Void> updateButTwoRewardsStatusTrue(Long id, Long rewardId) {
    sysActivityConfigClientService.updateButTwoRewardsStatusTrue(id, rewardId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addLotteryTurntable(AddLotteryTurntableCmd cmd) {
    sysActivityConfigClientService.addLotteryTurntable(cmd.getSysOrigin(),
        cmd.getActivityLotteryTurntableCache());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<ActivityLotteryTurntableCache> getLotteryTurntable(
      SysOriginPlatformEnum sysOrigin) {
    return ResultResponse.success(sysActivityConfigClientService.getLotteryTurntable(sysOrigin));
  }

}
