import { ActivityData } from "../../domain/activityField/activityField";
import { PopNoticeData } from "../../domain/activityField/popNotice";
import { ShopData } from "../../domain/roleField/shop";
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
import { getActivityById } from "./activityService";

/**
   * 玩家活动数据
   *
   * @param {number} serverId 区Id
   * @param {number} activityId 活动Id
   * @param {string} roleId 角色Id
   *
   */
 export async function getPopNoticeData(serverId: number, activityId: number, roleId: string) {
    let activityData = await getActivityById(activityId);
    let createTime = await getRoleCreateTime(roleId);
    let serverTime = await getServerCreateTime(serverId);

    let playerData = new PopNoticeData(activityData, createTime, serverTime);
    if(playerData.needActivityTime()) {
      let { activityId } = playerData.param;
      let curActivity = await getActivityById(activityId);
      let data = new ActivityData(curActivity, createTime, serverTime);
      playerData.setActivityTime(Math.floor(data.beginTime/1000), Math.floor(data.nextRefreshTime/1000));
    }
    if(playerData.needShopTime()) {
      let { activityId, shopItemId } = playerData.param;
      let curActivity = await getActivityById(activityId);
      let data = new ShopData(curActivity, createTime, serverTime);
      let item = data.findByItemId(shopItemId);
      if(item) playerData.setActivityTime(item.beginTime, item.endTime)
    }
    delete playerData.param;
    return playerData;
}