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

import com.red.circle.common.business.dto.cmd.IdStringCmd;
import com.red.circle.console.app.dto.clienobject.user.SpecialIdLogCO;
import com.red.circle.console.app.dto.clienobject.user.UserSpecialIdCO;
import com.red.circle.console.app.service.app.user.UserSpecialIdManagerService;
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.sys.PageUserSpecialIdCmd;
import com.red.circle.other.inner.model.cmd.user.UpdateUserSpecialIdCmd;
import com.red.circle.other.inner.model.cmd.user.UserSpecialIdCmd;
import com.red.circle.other.inner.model.cmd.user.UserSpecialIdExpiredTimeCmd;
import com.red.circle.other.inner.model.cmd.user.UserSpecialIdQryCmd;
import java.util.List;
import lombok.RequiredArgsConstructor;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户靓号id.
 *
 * @author pengliang on 2022/2/16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/user-special-id")
public class UserSpecialIdResetController extends BaseController {

  private final UserSpecialIdManagerService userSpecialIdManagerService;

  @OpsOperationReqLog("添加/修改靓号")
  @PostMapping("/add-or-update")
  public void addOrUpdate(@RequestBody @Validated UserSpecialIdCmd param) {
    param.setOptUserId(param.getReqUserId());
    userSpecialIdManagerService.addOrUpdate(param);
  }

  @OpsOperationReqLog("修改有效时间靓号")
  @PostMapping("/expired-time")
  public void expiredTime(
      @RequestBody @Validated UserSpecialIdExpiredTimeCmd param) {
    param.setOptUserId(param.getReqUserId());
    userSpecialIdManagerService.updateExpiredTime(param);
  }

  @OpsOperationReqLog("移除靓号")
  @PostMapping("/remove")
  public void remove(@RequestBody @Validated IdStringCmd cmd) {
    userSpecialIdManagerService.remove(cmd.getId(), cmd.getReqUserId());
  }

  /**
   * 数据查看.
   */
  @GetMapping("/flow")
  public List<UserSpecialIdCO> flow(UserSpecialIdQryCmd query) {
    return userSpecialIdManagerService.flow(query);
  }

  /**
   * 账号最近20条操作记录.
   */
  @GetMapping("/latest-log")
  public List<SpecialIdLogCO> listLatestLog(
      @RequestParam(value = "userId", required = false) Long userId) {
    return userSpecialIdManagerService.listLatestLog(userId);
  }

  @OpsOperationReqLog("修改靓号")
  @PostMapping("/update-account")
  public void updateAccount(@RequestBody @Validated UpdateUserSpecialIdCmd param) {
    param.setOptUserId(param.getReqUserId());
    userSpecialIdManagerService.updateAccount(param);
  }

  /**
   * 账号操作记录-分页查询.
   */
  @GetMapping("/page/latest-log")
  public PageResult<SpecialIdLogCO> pageSpecialIdLog(PageUserSpecialIdCmd param) {
    return userSpecialIdManagerService.pageSpecialIdLog(param);
  }
}
