import {CFlight} from '../classes/CFlight';
import {CHour} from '../classes/CHour';
import { IKey } from '../interfaces/IKey';

export class CSeason implements IKey
{
    public readonly id: string;
    public readonly distance: number;
    public readonly points: number;
    public readonly flightCount: number;
    public readonly flighttime: CHour;
    public readonly flighttimeDisp: string;
    public readonly flights: CFlight[];
    
    constructor(id: string, flights: CFlight[]) 
    {
        this.id = id;
        this.flights = flights;
        this.flighttime = new CHour(0)
        
        var Vals = this.calcValues();

        this.distance = Vals.Dist;
        this.points = Vals.Points;
        this.flightCount = Vals.Count;
        this.flighttimeDisp = this.flighttime.Print();
    }

    public get key()
    {
        return this.id;
    }

    private calcValues()
    {
        var sumDist: number = 0;
        var sumPoints: number = 0;
        for (let f of this.flights) 
        {
            this.flighttime.Add(f.FlightDuration);

            sumDist += +f.BestTaskDistance;
            sumPoints += +f.BestTaskPoints;
        }
        var count: number = this.flights.length;

        return (
        {
            'Dist': sumDist,
            'Points': sumPoints,
            'Count': count,
        });
    }
}