package com.red.circle.game.fruit.application.endpoint.impl;

import com.red.circle.game.fruit.application.convertor.GameFruitAppConvertor;
import com.red.circle.game.fruit.application.endpoint.GameFruitConfigClientService;
import com.red.circle.game.fruit.infrastructure.database.entity.GameCodeManage;
import com.red.circle.game.fruit.infrastructure.database.repository.GameCodeManageService;
import com.red.circle.game.fruit.infrastructure.database.repository.GameFruitPrizeService;
import com.red.circle.game.fruit.infrastructure.database.repository.GameFruitRuleService;
import com.red.circle.game.fruit.inner.model.cmd.GameCodeManageCmd;
import com.red.circle.game.fruit.inner.model.cmd.GameFruitPrizeCmd;
import com.red.circle.game.fruit.inner.model.cmd.GameFruitRuleCmd;
import com.red.circle.game.fruit.inner.model.dto.GameCodeManageDTO;
import com.red.circle.game.fruit.inner.model.dto.GameFruitPrizeDTO;
import com.red.circle.game.fruit.inner.model.dto.GameFruitRuleDTO;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 摩天轮游戏任务相关
 *
 * @author zongpubin on 2023/12/13
 */
@Service
@RequiredArgsConstructor
public class GameFruitConfigClientServiceImpl implements GameFruitConfigClientService {

  private final GameFruitAppConvertor gameFruitAppConvertor;
  private final GameFruitRuleService gameFruitRuleService;
  private final GameFruitPrizeService gameFruitPrizeService;
  private final GameCodeManageService gameCodeManageService;

  @Override
  public void updateRule(GameFruitRuleCmd cmd) {
    gameFruitRuleService.updateRule(gameFruitAppConvertor.toGameFruitRule(cmd));
  }

  @Override
  public GameFruitRuleDTO getRule(String sysOrigin) {
    return gameFruitAppConvertor.toGameFruitRuleDTO(gameFruitRuleService.getRule(sysOrigin));
  }


  @Override
  public void addPrize(GameFruitPrizeCmd cmd) {
    gameFruitPrizeService.add(gameFruitAppConvertor.toGameFruitPrize(cmd));
  }

  @Override
  public void updatePrize(GameFruitPrizeCmd cmd) {
    gameFruitPrizeService.update(gameFruitAppConvertor.toGameFruitPrize(cmd));
  }

  @Override
  public List<GameFruitPrizeDTO> listPrize(String sysOrigin) {
    return gameFruitAppConvertor.toListGameFruitPrizeDTO(gameFruitPrizeService.listPrize(sysOrigin));
  }

  @Override
  public Map<Long, GameCodeManageDTO> mapGameCodeManage(Set<Long> gameIds) {
    return gameCodeManageService.mapGameCodeManage(gameIds);
  }


  @Override
  public void addGameCode(GameCodeManageCmd gameCodeManage) {
    gameCodeManageService.add(new GameCodeManage().setGameCode(gameCodeManage.getGameCode())
        .setGameId(gameCodeManage.getGameId())
        .setGameName(gameCodeManage.getGameName())
        .setSysOrigin(gameCodeManage.getOrigin()));
  }

  @Override
  public void delGameCode(Long gameId) {
    gameCodeManageService.del(gameId);
  }
}
