package com.red.circle.other.infra.database.mongo.service.gift.impl;

import com.red.circle.other.infra.database.mongo.entity.gift.PremiumGiftWallMongo;
import com.red.circle.other.infra.database.mongo.service.gift.PremiumGiftWallMongoService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

/**
 * 高级礼物墙.
 *
 * @author pengshigang on 2022/8/10
 */
@Service
@RequiredArgsConstructor
public class PremiumGiftWallMongoServiceImpl implements PremiumGiftWallMongoService {

  private final MongoTemplate mongoTemplate;

  @Override
  public void add(PremiumGiftWallMongo premiumGiftWallMongo) {
    mongoTemplate.save(premiumGiftWallMongo);
  }

  @Override
  public List<PremiumGiftWallMongo> giftWalls(String sysOrigin, Integer size) {
    return mongoTemplate
        .find(Query.query(Criteria.where("sysOrigin").is(sysOrigin))
            .with(Sort.by(Sort.Order.desc("createTime")))
            .limit(size), PremiumGiftWallMongo.class);
  }

}
