package com.red.circle.other.app.inner.endpoint.material.props;

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.material.props.BadgeBackpackClientService;
import com.red.circle.other.inner.endpoint.material.props.api.BadgeBackpackClientApi;
import com.red.circle.other.inner.model.cmd.material.DeleteBadgeCmd;
import com.red.circle.other.inner.model.cmd.material.GiveBadgeCmd;
import com.red.circle.other.inner.model.dto.material.BadgeBackpackDTO;
import com.red.circle.other.inner.model.dto.material.BadgePictureConfigDTO;
import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import java.util.List;
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/3
 */
@Validated
@RestController
@RequestMapping(value = BadgeBackpackClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class BadgeBackpackClientEndpoint implements BadgeBackpackClientApi {

  private final BadgeBackpackClientService badgeBackpackClientService;

  @Override
  public ResultResponse<List<UseBadgeDTO>> listUseBadge(Long userId, String sysOrigin,
      Set<Long> wearBadgeId) {
    return ResultResponse.success(badgeBackpackClientService.listUseBadge(
        userId, sysOrigin, wearBadgeId
    ));
  }

  @Override
  public ResultResponse<List<BadgeBackpackDTO>> listUseBadgeBackpackByUserId(Long userId) {
    return ResultResponse.success(badgeBackpackClientService.listUseBadgeBackpackByUserId(userId));
  }

  @Override
  public ResultResponse<Void> updateUseBadge(Long userId, Set<Long> badgeIds) {
    badgeBackpackClientService.updateUseBadge(userId, badgeIds);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> useOffByUserId(Long userId) {
    badgeBackpackClientService.useOffByUserId(userId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> useOffByIds(Set<Long> ids) {
    badgeBackpackClientService.useOffByIds(ids);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> reduceDaysAndUnUse(Long userId, Set<Long> badgeIds,
      Integer reduceDays) {
    badgeBackpackClientService.reduceDaysAndUnUse(userId, badgeIds, reduceDays);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> activationPermanentAndUse(Long userId, Long badgeId) {
    return ResultResponse.success(
        badgeBackpackClientService.activationPermanentAndUse(userId, badgeId)
    );
  }

  @Override
  public ResultResponse<Boolean> activationTemporaryAndUse(Long userId, Long badgeId,
      Integer days) {
    return ResultResponse.success(
        badgeBackpackClientService.activationTemporaryAndUse(userId, badgeId, days)
    );
  }

  @Override
  public ResultResponse<Void> deleteBadge(DeleteBadgeCmd cmd) {
    badgeBackpackClientService.deleteBadge(cmd.getUserIds(), cmd.getBadgeIds());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> saveBatchBackpack(List<BadgeBackpackDTO> badges) {
    badgeBackpackClientService.saveBatchBackpack(badges);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> saveBackpack(BadgeBackpackDTO badge) {
    badgeBackpackClientService.saveBackpack(badge);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<BadgeBackpackDTO>> listUseNotExpireTimeByUserIds(Set<Long> userIds) {
    return ResultResponse.success(
        badgeBackpackClientService.listUseNotExpireTimeByUserIds(userIds)
    );
  }

  @Override
  public ResultResponse<Void> deleteUserBadge(Long userId, Long badgeId) {
    badgeBackpackClientService.deleteUserBadge(userId, badgeId);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Void> deleteBadge(Long userId, Long badgeId) {
    badgeBackpackClientService.deleteBadge(userId, badgeId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeWearByIds(Set<Long> ids) {
    badgeBackpackClientService.removeWearByIds(ids);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<BadgePictureConfigDTO>> listBadge(Long userId, String sysOrigin) {
    return ResultResponse.success(badgeBackpackClientService.listBadge(userId, sysOrigin));
  }

  /**
   * 发送货运代理徽章
   */
  @Override
  public ResultResponse<Void> giveBadgePermanent(Long badgeId, Long userId) {
    badgeBackpackClientService.giveBadgePermanent(badgeId, userId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> giveBadge(GiveBadgeCmd cmd) {
    badgeBackpackClientService.giveBadge(cmd);
    return ResultResponse.success();
  }

}
