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

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.material.gift.GiftBackpackClientService;
import com.red.circle.other.inner.endpoint.material.gift.api.GiftBackpackClientApi;
import com.red.circle.other.inner.model.cmd.material.GiftBackpackLimitCmd;
import com.red.circle.other.inner.model.dto.material.GiftBackpackDTO;
import com.red.circle.other.inner.model.dto.material.GiftBackpackLimitDTO;
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/5
 */
@Validated
@RestController
@RequestMapping(value = GiftBackpackClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class GiftBackpackClientEndpoint implements GiftBackpackClientApi {

  private final GiftBackpackClientService giftBackpackClientService;

  @Override
  public ResultResponse<Void> deleteByIds(List<Long> ids) {
    giftBackpackClientService.deleteByIds(ids);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<GiftBackpackDTO>> listUserGiftBackPack(Long userId) {
    return ResultResponse.success(giftBackpackClientService.listUserGiftBackPack(userId));
  }

  @Override
  public ResultResponse<GiftBackpackDTO> incrGift(Long userId, Long giftId, Integer quantity) {
    return ResultResponse.success(giftBackpackClientService.incrGift(userId, giftId, quantity));
  }

  @Override
  public ResultResponse<Void> addLimit(GiftBackpackLimitDTO limit) {
    giftBackpackClientService.addLimit(limit);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> incrGiftAndLimit(GiftBackpackLimitCmd limit) {
    giftBackpackClientService.incrGiftAndLimit(limit);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeUserCpGift(Set<Long> userIds) {
    giftBackpackClientService.removeUserCpGift(userIds);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> consumerGifts(Long id, Long giftId, Long userId,
      Integer quantity) {
    return ResultResponse.success(
        giftBackpackClientService.consumerGifts(id, giftId, userId, quantity));
  }

  @Override
  public ResultResponse<GiftBackpackDTO> getUserGift(Long userId, Long giftId) {
    return ResultResponse.success(
        giftBackpackClientService.getUserGift(userId, giftId)
    );
  }

  @Override
  public ResultResponse<Void> deductGift(Long userId, Long giftId, Integer quantity) {
    giftBackpackClientService.deductGift(userId, giftId, quantity);
    return ResultResponse.success();
  }

}
