import * as moment from 'moment';

export interface AppSettings {
    showDebugVersion: boolean;
    buyPeriod: {
        min: number;
        max: number;
    };
    refreshInterval: number;
    flightStatusAvailableFrom: number;
    boardSearchFrom: number;
    boardSearchTo: number;
    scheduleSearchFrom: number;
    scheduleSearchTo: number;    
    flightsMapSearchFrom: number;
    flightsMapSearchTo: number;
    boardMaxDate: Date;
    boardMinDate: Date;
    scheduleMaxDate: Date;
    scheduleMinDate: Date;
    //intervalId: number | null;
    //startValidationDatesUpdatingInterval(): void;
    //stopValidationDatesUpdatingInterval(): void;
}
export const defaultSettings: AppSettings = {
    showDebugVersion: false,
    buyPeriod: {
        min: 2,
        max: 330,
    },
    refreshInterval: 3 * 60 * 1000, // 3 min
    // refreshInterval: 5 * 1000, // 5 sec
    flightStatusAvailableFrom: 2,
    boardSearchFrom: 1,
    boardSearchTo: 7,
    scheduleSearchFrom: 1,
    scheduleSearchTo: 330,    
    flightsMapSearchFrom: 1,
    flightsMapSearchTo: 186,
    boardMaxDate: new Date(),
    boardMinDate: new Date(),
    scheduleMaxDate: new Date(),
    scheduleMinDate: new Date(),
    //intervalId: null,
    //startValidationDatesUpdatingInterval() {
        // always clear previous interval because appSettings instance can be
        // shared between several components; So calling settings.observeDayChange
        // from different parts will cause this.intervalId rewrite and other
        // intervals won't be cleared.
        // if (this.intervalId) {
        //     this.stopValidationDatesUpdatingInterval();
        // }

        // this.intervalId = setInterval(() => {
        //     this.boardMaxDate = moment().startOf('day').add(this.boardSearchTo, 'day').toDate();
        //     this.boardMinDate = moment().startOf('day').add(-this.boardSearchFrom, 'day').toDate();
        //     this.scheduleMaxDate = moment().startOf('day').add(this.scheduleSearchTo, 'day').toDate();
        //     this.scheduleMinDate = moment().startOf('day').add(-this.scheduleSearchFrom, 'day').toDate();
        //     this.flightsMapMaxDate = moment().startOf('day').add(this.flightsMapSearchTo, 'day').toDate();
        //     this.flightsMapMinDate = moment().startOf('day').add(-this.flightsMapSearchFrom, 'day').toDate();
        // }, 60 * 1000);
    // },
    // stopValidationDatesUpdatingInterval() {
    //     if (!this.intervalId) {
    //         return; //already cleared
    //     }

    //     clearInterval(this.intervalId);
    //     this.intervalId = null;
    // },
};
export interface AppSettingsContract {
    showDebugVersion: string;
    uiOptions: UIOptionsConfiguration;
}

export interface UIOptionsConfiguration {
    isTestVersion: string;
    filter: UIOptionsFilterConfiguration;
    buttons: UIOptionsButtonsConfiguration;
}

export interface UIOptionsFilterConfiguration {
    schedule: UIOptionsFilterScheduleConfiguration;
    onlineboard: UIOptionsFilterOnlineboardConfiguration;
}

export interface UIOptionsFilterScheduleConfiguration {
    searchFrom: string;
    searchTo: string;
    timeStep: string;
}


export interface UIOptionsFilterOnlineboardConfiguration {
    searchFrom: string;
    searchTo: string;
    timeStep: string;
}

export interface UIOptionsButtonsConfiguration {
    buyTicket: UIOptionsButtonsBuyTicketConfiguration;
    flightStatus: UIOptionsButtonsFlightStatusConfiguration;
}

export interface UIOptionsButtonsBuyTicketConfiguration {
    period: UIOptionsButtonsBuyTicketPeriodConfiguration;
}

export interface UIOptionsButtonsBuyTicketPeriodConfiguration {
    max: string;
    min: string;
}

export interface UIOptionsButtonsFlightStatusConfiguration {
    visible: string;
    availableFrom: string;
}
