import { FormControl } from '@angular/forms';

import { Profile } from './profile.model';
import { ColumnDefinition, PageLinks, PageMeta } from './shared.model';

export interface Jump {
    slug: string;
    date: string;
    numero: number;
    lieu?: string;
    oaci?: string;
    aeronef?: string;
    imat?: string;
    hauteur?: number;
    deploiement?: number;
    voile?: string;
    taille?: number;
    categorie?: string;
    module?: string;
    participants?: number;
    sautants: Array<string>;
    programme?: string;
    accessoires?: string;
    zone?: string;
    dossier?: string;
    video?: string;
    files: Array<JumpFile>;
    x2data: X2Data;
    author: Profile;
    createdAt: string;
    updatedAt: string;
    //isEdit?: boolean;
    isSelected?: boolean;
}

export enum JumpFileType {
    CSV = "csv",
    IMAGE = "image",
    KML = "kml",
    VIDEO = "video"
}

export interface JumpFile {
    slug: string;
    name: string;
    path: string;
    type: JumpFileType;
}

export interface JumpForm {
    date: FormControl<string>;
    numero: FormControl<number>;
    lieu: FormControl<string>;
    oaci: FormControl<string>;
    aeronef: FormControl<string>;
    imat: FormControl<string>;
    hauteur: FormControl<number>;
    deploiement: FormControl<number>;
    voile: FormControl<string>;
    taille: FormControl<number>;
    categorie: FormControl<string>;
    module: FormControl<string>;
    participants: FormControl<number>;
    //sautants: FormControl<Array<string>>;
    programme: FormControl<string>;
    accessoires: FormControl<string>;
    zone: FormControl<string>;
    dossier: FormControl<string>;
    video: FormControl<string>;
}

export interface JumpAddParams {
    numeros: string;
    date: string;
    video: boolean;
}

export interface JumpByDate {
    month: number;
    year: number;
    count: number;
}

export interface JumpByCategorie {
    categorie: string;
    count: number;
}

export interface JumpByDay {
    jumps: Array<Partial<Jump>>;
    count: number;
}

export interface JumpByModule {
    categorie: string;
    module: string;
    count: number;
}

export interface JumpByDateByModule {
    categorie: string;
    module: string;
    year: number;
    month: number;
    count: number;
}

export interface JumpYears {
    year: number;
    count: number;
}

export interface SkydiverIdJumps {
    items: Array<X2Data>;
    _links: PageLinks;
    _meta: PageMeta;
}

export interface X2Data {
    id: string;
    name: string;
    type: string;
    description: string;
    landingZone: string;
    speed: {
        freeFall: {
            vertical: {
                max: number;
                avg: number;
            };
            horizontal: {
                max: number;
                avg: number;
            };
        };
        underCanopy: {
            vertical: {
                max: number;
                avg: number;
            };
            horizontal: {
                max: number;
                avg: number;
            };
        };
    };
    glideRatio: {
        freeFall: {
            max: number;
            avg: number;
        };
        underCanopy: {
            max: number;
            avg: number;
        };
    };
    duration: {
        freeFall: number;
        underCanopy: number;
    };
    distance: {
        exitFromLandingZone: number;
        totalFlying: number;
        totalHorizontal: number;
    };
    altitude: {
        exit: number;
        deployment: number;
    };
    cutaway: string;
    malfunctions:Array<
        {
            name: string;
            type: string;
        }
    >;
    date: string;
    createdOn: string;
}

export interface JumpPageData {
    jump: Jump;
    prevJump: Jump;
    nextJump: Jump;
    _links: PageLinks;
    _meta: PageMeta;
}

export interface JumpsPageData {
    jumpsByCategory: Array<JumpByCategorie>;
    jumpsByDate: Array<JumpByDate>;
    jumpsByDateByModule: Array<JumpByDateByModule>;
    jumpsByModule: Array<JumpByModule>;
    jumpsByYears: Array<JumpYears>;
    //jumpsFromSkydiverIdApi: SkydiverIdJumps;
    lastjump: Jump;
    /*yearsCount: number;
    jumpsByCategoryCount: number;
    jumpsByDateCount: number;
    jumpsByModuleCount: number;*/
}

export const jumpColumns: Array<ColumnDefinition> = [
    {
        key: 'isSelected',
        type: 'isSelected',
        label: ''
    },
    {
        key: 'date',
        type: 'date',
        label: 'Date',
        required: true
    },
    {
        key: 'numero',
        type: 'numeric',
        label: 'Numéro',
        required: true,
        min: 0,
        step: 1
    },
    {
        key: 'lieu',
        type: 'text',
        label: 'Lieu'
    },
    {
        key: 'oaci',
        type: 'text',
        label: 'OACI'
    },
    {
        key: 'aeronef',
        type: 'text',
        label: 'Aéronef'
    },
    {
        key: 'imat',
        type: 'text',
        label: 'Imat.'
    },
    {
        key: 'hauteur',
        type: 'numeric',
        label: 'Hauteur'
    },
    {
        key: 'deploiement',
        type: 'numeric',
        label: 'Deploiement'
    },
    {
        key: 'voile',
        type: 'text',
        label: 'Voile'
    },
    {
        key: 'taille',
        type: 'numeric',
        label: 'Taille'
    },
    {
        key: 'categorie',
        type: 'text',
        label: 'Categorie'
    },
    {
        key: 'module',
        type: 'text',
        label: 'Module'
    },
    {
        key: 'participants',
        type: 'numeric',
        label: 'Participants'
    },
    {
        key: 'sautants',
        type: 'text',
        label: 'Sautants'
    },
    {
        key: 'programme',
        type: 'text',
        label: 'Programme'
    },
    {
        key: 'accessoires',
        type: 'text',
        label: 'Accessoires'
    },
    {
        key: 'zone',
        type: 'text',
        label: 'Zone'
    },
    /*{
        key: 'dossier',
        type: 'text',
        label: ''
    },*/
    {
        key: 'video',
        type: 'text',
        label: 'Vidéo'
    },
    {
        key: 'isEdit',
        type: 'isEdit',
        label: ''
    }
];