#!/usr/bin/env python

from datetime import datetime, timedelta

from aman.types.ArrivalRoute import ArrivalRoute

class ArrivalData:
    def __init__(self, **kargs):
        self.Star = None
        self.MaximumTimeToGain = None
        self.MaximumTimeToLose = None
        self.InitialArrivalTime = None
        self.EarliestArrivalTime = None
        self.LatestArrivalTime = None
        self.ArrivalRoute = None
        self.Trackmiles = None

        for key, value in kargs.items():
            if 'ttg' == key:
                if True == isinstance(value, timedelta):
                    self.MaximumTimeToGain = value
                elif True == isinstance(value, (int, float)):
                    self.MaximumTimeToGain = timedelta(seconds = float(value))
                else:
                    raise Exception('Invalid type for ttg')
            elif 'ttl' == key:
                if True == isinstance(value, timedelta):
                    self.MaximumTimeToLose = value
                elif True == isinstance(value, (int, float)):
                    self.MaximumTimeToLose = timedelta(seconds = float(value))
                else:
                    raise Exception('Invalid type for ttl')
            elif 'star' == key:
                if True == isinstance(value, ArrivalRoute):
                    self.Star = value
                else:
                    raise Exception('Invalid type for star')
            elif 'ita' == key:
                if True == isinstance(value, datetime):
                    self.InitialArrivalTime = value
                else:
                    raise Exception('Invalid type for ita')
            elif 'earliest' == key:
                if True == isinstance(value, datetime):
                    self.EarliestArrivalTime = value
                else:
                    raise Exception('Invalid type for earliest')
            elif 'latest' == key:
                if True == isinstance(value, datetime):
                    self.LatestArrivalTime = value
                else:
                    raise Exception('Invalid type for latest')
            elif 'route' == key:
                self.ArrivalRoute = value
            elif 'trackmiles' == key:
                self.Trackmiles = value
            else:
                raise Exception('Unknown key: ' + key)
