
import * as moment from "moment";
import { ADDICTION_PREVENTION_CODE, TEEN_DAILY_MAX_TIME, TEEN_HOLIDAY_MAX_TIME } from "../consts";
import { gameData } from './data';

export function checkTeeanAgerTime(isAdult: boolean, todaySumTime: number) {
    if(isAdult) return ADDICTION_PREVENTION_CODE.SUCCESS;

    let now = new Date();
    let hour = now.getHours();
    if(hour < 8 || hour > 22) return ADDICTION_PREVENTION_CODE.CURFEW;

    let isHoliday = checkIsHoliday();
    if(isHoliday && todaySumTime > TEEN_HOLIDAY_MAX_TIME) {
        return ADDICTION_PREVENTION_CODE.HOLIDAY;
    } else if (!isHoliday && todaySumTime > TEEN_DAILY_MAX_TIME) {
        return ADDICTION_PREVENTION_CODE.WORKDAY;
    }
    return ADDICTION_PREVENTION_CODE.SUCCESS;
}

export function checkIsHoliday() {
    let now = new Date();
    let day = now.getDay();
    let str = moment().format('YYYY-MM-DD');
    return day == 0 || day == 6 || gameData.holiday.indexOf(str) != -1;
}