package com.red.circle.game.fruit.infrastructure.database.memory.service.impl;

import com.red.circle.game.fruit.application.dto.GameTimelineManage;
import com.red.circle.game.fruit.core.memory.TimeSecondCounter;
import com.red.circle.game.fruit.core.memory.TypeCounter;
import com.red.circle.game.fruit.infrastructure.database.memory.key.GameFruitMemoryKeys;
import com.red.circle.game.fruit.infrastructure.database.memory.service.GameFruitMemoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author pengliang on 2020/10/9
 */
@Service
@RequiredArgsConstructor
public class GameFruitMemoryServiceImpl implements GameFruitMemoryService {

  /**
   * 1.本轮游戏总押注（游戏开奖使用， 新游戏开始清理） 2.游戏总时间控制（游戏进行到哪里的时间） 3.游戏的配置 （策略） --- 其他 押注接口： 点一下就是一个请求
   * gameId,type,amount gameId+type += amount
   */
  private final static TypeCounter typeCounter = new TypeCounter();
  private final static TimeSecondCounter timeSecondCounter = new TimeSecondCounter(
      GameTimelineManage.totalSecond);

  @Override
  public void incrPrizeBet(Long prizeId, Integer amount) {
    typeCounter.increment(GameFruitMemoryKeys.ROUND_PRIZE_BET.getKey(String.valueOf(prizeId)),
        amount);
  }

  @Override
  public int getBetCache(Long prizeId) {
    return typeCounter.getCount(
        GameFruitMemoryKeys.ROUND_PRIZE_BET.getKey(String.valueOf(prizeId)));
  }

  @Override
  public void removePrizeBet() {
    typeCounter.clear();
  }

  @Override
  public int getRoundSec() {
    return timeSecondCounter.get();
  }

  @Override
  public void putRoundSec(Integer sec) {
    timeSecondCounter.set(sec);
  }

  @Override
  public void decrRoundSec() {
    timeSecondCounter.decrement();
    //System.out.println("秒数====" + getRoundSec());
  }


  @Override
  public void incrRoundSec() {
    timeSecondCounter.increment();
    //System.out.println("秒数====" + getRoundSec());
  }
}
