import { Injectable } from '@angular/core';

@Injectable()
export class CanActivateRedirrect {
    public validateStation(station: string) {
        if (!station) {
            return true;
        }

        const pattern: RegExp = /[A-Z]{3}/g;
        let match = station.match(pattern);

        return match && match[0] == station;
    }

    public validateTimeRange(timeFrom: string, timeTo: string) {
        const pattern: RegExp = /\d{4}/g;

        if (!timeFrom && !timeTo) {
            return true;
        }

        let matchFrom = timeFrom.match(pattern);
        let matchTo = timeTo.match(pattern);

        return matchFrom && matchFrom[0] == timeFrom && matchTo && matchTo[0] == timeTo;
    }

    public validateFlightNumber(number: string) {
        const pattern: RegExp = /\d{4}/g;
        let match = number.match(pattern);

        return match && match[0] == number
    }
}