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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
import com.red.circle.other.app.dto.clientobject.activity.*;
import com.red.circle.other.app.dto.clientobject.activity.InviteActivityCO.InviteActivityInfoCO;
import com.red.circle.other.app.dto.cmd.activity.InviteUserActivityLimitCmd;
import com.red.circle.other.app.service.activity.InviteUserActivityService;
import com.red.circle.other.app.dto.cmd.activity.BindInviteCodeCmd;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 邀请用户注册活动 前端控制器.
 * </p>
 *
 * @author lisizhe on 2023/9/25
 * @eo.api-type http
 * @eo.groupName 活动服务.邀请用户注册活动
 * @eo.path /activity/invite/user
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/activity/invite/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class InviteUserActivityRestController {

  private final InviteUserActivityService inviteUserActivityService;

  /**
   * 已提取列表.
   *
   * @eo.name 已提取列表
   * @eo.url /extract/list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/extract/list")
  public List<InviteActivityInfoCO> extractList(AppExtCommand cmd) {
    return inviteUserActivityService.extractList(cmd);
  }

  /**
   * 提取.
   *
   * @eo.name 提取
   * @eo.url /extract
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/extract")
  public void extract(AppExtCommand cmd) {
    inviteUserActivityService.extract(cmd);
  }

  /**
   * 邀请活动.
   *
   * @eo.name 邀请活动
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping
  public InviteActivityCO inviteActivity(AppExtCommand cmd) {
    return inviteUserActivityService.inviteActivity(cmd);
  }

  /**
   * 汇总.
   *
   * @eo.name 汇总
   * @eo.url /summary
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/summary")
  public InviteUserActivitySummaryCO getSummary(AppExtCommand cmd) {
    return inviteUserActivityService.getSummary(cmd);
  }

  /**
   * 邀请用户列表.
   *
   * @eo.name 邀请用户列表
   * @eo.url /list/invite/user
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/invite/user")
  public List<InviteUserCO> listInviteUser(InviteUserActivityLimitCmd cmd) {
    return inviteUserActivityService.listInviteUser(cmd);
  }

  /**
   * 被邀请佣金明细.
   *
   * @eo.name 被邀请佣金明细
   * @eo.url /list/commission/details
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/commission/details")
  public List<InviteUserCommissionDetailsCO> listUserCommissionDetails(
      InviteUserActivityLimitCmd cmd) {
    return inviteUserActivityService.listUserCommissionDetails(cmd);
  }

  /**
   * 邀请用户奖励池 - 奖励池.
   *
   * @eo.name 邀请用户奖励池
   * @eo.url /award/pool
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/award/pool")
  public List<ActivityUserRewardPropsCO> rewardPool(AppExtCommand cmd) {
    return inviteUserActivityService.listRewardPool(cmd);
  }

  /**
   * 邀请用户领取奖励.
   *
   * @eo.name 邀请用户领取奖励
   * @eo.url /receive/award
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/receive/award")
  public void receiveAward(AppIdLongCmd cmd) {
//    ResponseAssert.failure(CommonErrorCode.API_DEPRECATED);
    inviteUserActivityService.receiveAward(cmd);
  }
  /**
   * 获取我的邀请码.
   *
   * @eo.name 获取我的邀请码
   * @eo.url /my/invite/code
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/my/invite/code")
  public InviteCodeCO getMyInviteCode(AppExtCommand cmd) {
    InviteCodeCO inviteCode = inviteUserActivityService.getMyInviteCode(cmd);
    return inviteCode;
  }

  /**
   * 绑定邀请码.
   *
   * @eo.name 绑定邀请码
   * @eo.url /bind/invite/code
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/bind/invite/code")
  public void bindInviteCode(@Validated @RequestBody BindInviteCodeCmd cmd) {
    inviteUserActivityService.bindInviteCode(cmd);
  }

  /**
   * 邀请收益统计.
   *
   * @eo.name 邀请收益统计
   * @eo.url /income/statistics
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/income/statistics")
  public InviteIncomeStatisticsCO getIncomeStatistics(AppExtCommand cmd) {
    InviteIncomeStatisticsCO statistics = inviteUserActivityService.getIncomeStatistics(cmd);
    return statistics;
  }

  /**
   * 有效邀请用户列表.
   *
   * @eo.name 有效邀请用户列表
   * @eo.url /valid/invite/users
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/valid/invite/users")
  public List<ValidInviteUserCO> getValidInviteUsers(AppExtCommand cmd) {
    List<ValidInviteUserCO> users = inviteUserActivityService.getValidInviteUsers(cmd);
    return users;
  }


  /**
   * 获取我的邀请人信息
   * <p>
   * 返回当前用户的基本信息及其邀请人的信息
   *
   * @return 我的邀请人信息
   */
  @GetMapping("/my-inviter-info")
  public MyInviterInfoCO getMyInviterInfo(AppExtCommand cmd) {
    return inviteUserActivityService.getMyInviterInfo(cmd);
  }
}
