import { ACTIVITY_TYPE } from '../../consts';
import { ActivityModel, ActivityModelType } from '../../db/Activity';
import { ActivityDailyGiftsModel, ActivityDailyGiftsModelType } from '../../db/ActivityDailyGifts';
import { RoleModel } from '../../db/Role';
import { ServerlistModel } from '../../db/Serverlist';
import { DailyGiftsData } from '../../domain/activityField/dailyGiftsField';
import { getRoleCreateTime, getServerCreateTime } from '../redisService';
import { getActivitiesByType, getActivityById } from './activityService';



/**
   * 获取活动数据
   *
   * @param {number} serverId 区Id
   * @param {number} activityId 活动Id
   * @param {string} roleId 角色Id
   *
   */
export async function dailyGiftsActivity(serverId: number, roleId: string) {
    let activityDataArray = await getActivitiesByType(serverId, ACTIVITY_TYPE.DAILY_DISCOUNT_GIFT);
    if (activityDataArray.length === 0) {
        return null;
    }
    let activityData: ActivityModelType = activityDataArray[0];
    let playerRecords: ActivityDailyGiftsModelType[] = await ActivityDailyGiftsModel.findData(serverId, activityData.activityId, roleId);
    let createTime = await getRoleCreateTime(roleId);
    let serverTime = await getServerCreateTime(serverId);
    let playerData = new DailyGiftsData(activityData, createTime, serverTime);
    playerData.setPlayerRecords(playerRecords);
    return playerData;
}


/**
   * 玩家玩家活动数据
   *
   * @param {number} serverId 区Id
   * @param {number} activityId 活动Id
   * @param {string} roleId 角色Id
   *
   */
export async function getPlayerDailyGiftsData(activityId: number, serverId: number, roleId: string) {
    let activityData: ActivityModelType = await getActivityById(activityId);
    let playerRecords: ActivityDailyGiftsModelType[] = await ActivityDailyGiftsModel.findData(serverId, activityId, roleId);
    let createTime = await getRoleCreateTime(roleId);
    let serverTime = await getServerCreateTime(serverId);
    let playerData = new DailyGiftsData(activityData, createTime, serverTime);
    playerData.setPlayerRecords(playerRecords);

    return playerData;
}


