#!/usr/bin/env python

import pytz

from datetime import datetime

from aman.com import AircraftReport_pb2
from aman.sys.WeatherModel import WeatherModel
from aman.types.PerformanceData import PerformanceData

class Inbound:
    def __init__(self, report : AircraftReport_pb2.AircraftReport, performanceData : PerformanceData):
        self.Report = report
        self.Callsign = report.aircraft.callsign
        self.CurrentPosition = report.position
        self.ReportTime = datetime.strptime(report.reportTime + '+0000', '%Y%m%d%H%M%S%z').replace(tzinfo = pytz.UTC)
        self.InitialArrivalTime = None
        self.PlannedArrivalTime = None
        self.PlannedRunway = None
        self.PlannedStar = None
        self.PlannedArrivalRoute = None
        self.PlannedTrackmiles = None
        self.FixedSequence = False
        self.WTC = None

        # analyze the WTC
        wtc = report.aircraft.wtc.upper()
        if 'L' == wtc or 'M' == wtc or 'H' == wtc or 'J' == wtc:
            self.WTC = wtc

        # search performance data -> fallback to A320
        if self.Report.aircraft.type in performanceData.Aircrafts:
            self.PerformanceData = performanceData.Aircrafts[self.Report.aircraft.type]
        if None == self.PerformanceData:
            self.PerformanceData = performanceData.Aircrafts['A320']
