export type Entity = {
    id : string,
    deleted: boolean,
};

export enum MediaInfoType
{
    Image,
    Video,
    Link,
    OtherFile
}

export type MediaInfo = {
    type: MediaInfoType,
    contentType: string,
    objectId: string,
    url?: string | null
}

export type Language = {
    codeIso3: string,
    name: string,
    icon?: MediaInfo,
} & Entity

export type Genre = {
    name: string,
} & Entity

export enum NameType
{
    Original,
    OriginalInAnotherLanguage,
    Translation,
    Abbreviation,
}

export type NameItem = {
    value: string,
    type: NameType,
    language: Language,
}

export type Description = {
    value: string,
    isOriginal: boolean,
    language: Language,
}

export type GenreProportion = {
    proportion: number | null,
    genre: Genre,
}

export type CommonProperties = {
    names: Array<NameItem>,
    preview?: MediaInfo | null,
    descriptions: Array<Description>,
    genres: Array<GenreProportion>,
    relatedContent: Array<MediaInfo>,
    // announcementDate?: string | Date | null,
    announcementDate?: string | null,
    // estimatedReleaseDate?: Date | null,
    estimatedReleaseDate?: string | null,
    // releaseDate?: Date | null,
    releaseDate?: string | null,
}

export type AnimeItem = {
    completed: boolean,
    commonProperties: CommonProperties,
    number?: number,
    order: number,
    expirationTime: Date,

    $type: string,
} & Entity

export enum AnimeEpisodeType
{
    Regular,
    Ova,
    Ona,
}

export type Episode = {
    variant: number,
    type: AnimeEpisodeType,
    durationTicks: number,
    durationType: AnimeItemSingleDurationType,
} & AnimeItem


export type EpisodeShort = {
    id : string,
    number: number,
    order: number,
    variant: number,
    type: AnimeEpisodeType,
    durationTicks: number,
    durationType: AnimeItemSingleDurationType,
    names: Array<NameItem>,
    preview?: MediaInfo | null,
    releaseDate?: string | null,
}

export enum AnimeItemSingleDurationType{
    Series,
    FullLength,
    Special,
}

export type Season = {
    episodes: Array<Episode>,
    director?: string,
    originCountry?: string,
} & AnimeItem

export type AnimeTitleShort = {
    id : string,

    rate?: number,
    myRate?: number,

    views?: number,
    myViews?: number,
    
    names: Array<NameItem>,
    preview?: MediaInfo | null,
    genres: Array<GenreProportion>,
    // estimatedReleaseDate?: Date | null,
    estimatedReleaseDate?: string | null,
    // releaseDate?: Date | null,
    releaseDate?: string | null,

    seasonsCount: number,
    episodesCount: number,
    episodesInsideSeasonsCount: number,
    completed: boolean,
}

export type AnimeTitleDetail = {
    commonProperties: CommonProperties,

    rate?: number,
    myRate?: number,

    views?: number,
    myViews?: number,

    items: Array<AnimeItem>,
    
    seasonsCount: number,
    episodesCount: number,
    episodesInsideSeasonsCount: number,

    completed: boolean,
} & Entity

export interface AnimeTitle extends Entity {
    commonProperties: CommonProperties,

    containRates: boolean,
    containViews: boolean,

    items: Array<Season | Episode>,

    completed: boolean,
    expirationTimeTicks: number,
}

export type ProblemDetails = {
    type?: string,
    title?: string,
    status?: number,
    detail?: string,
    instance?: string,
    extensions: Map<string, object>
}

/* POST Models */

export type AnimeTitleCreateModel = {
    preview?: CreateMediaInfoModel | null,
    names: Array<CreateNameModel>,
    descriptions: Array<CreateDescriptionModel>,
    relatedContent: Array<CreateMediaInfoModel>,
    genres: Array<CreateGenreProportionModel>,
    announcementDate?: Date | null,
    estimatedReleaseDate?: Date | null,
    releaseDate?: Date | null,
}

export type AnimeSeasonCreateModel = {
    animeTitleId: string,
    preview?: CreateMediaInfoModel | null,
    names: Array<CreateNameModel>,
    descriptions: Array<CreateDescriptionModel>,
    relatedContent: Array<CreateMediaInfoModel>,
    genres: Array<CreateGenreProportionModel>,
    announcementDate?: Date | null,
    estimatedReleaseDate?: Date | null,
    // releaseDate?: Date | null,
    number?: number | null,
}

export type AnimeSeasonDeleteModel = {
    animeTitleId: string,
    animeSeasonId: string,
}


export type AnimeEpisodeCreateModel = {
    animeTitleId: string,
    animeSeasonId?: string | null,
    type: AnimeEpisodeType,
    preview?: CreateMediaInfoModel | null,
    names: Array<CreateNameModel>,
    descriptions: Array<CreateDescriptionModel>,
    relatedContent: Array<CreateMediaInfoModel>,
    genres: Array<CreateGenreProportionModel>,
    announcementDate?: Date | null,
    estimatedReleaseDate?: Date | null,
    releaseDate?: Date | null,
    number?: number | null,
    order?: number | null,
    durationTicks?: number | null,
}

export type AnimeEpisodeDeleteModel = {
    animeTitleId: string,
    animeSeasonId?: string | null,
    animeEpisodeId: string,
}

export type CreateNameModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    languageId: string,
    value: string,
    type: NameType,
}
export type EditNameModel = {
    newLanguageId?: string | null,
    newValue?: string | null,
} & CreateNameModel
export type DeleteNameModel = { } & CreateNameModel



export type CreateDescriptionModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    languageId: string,
    value: string,
    isOriginal: boolean,
}
export type EditDescriptionModel = {
    newLanguageId?: string | null,
    newValue?: string | null,
} & CreateDescriptionModel
export type DeleteDescriptionModel = { } & CreateDescriptionModel

export type CreateMediaInfoModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    newType: MediaInfoType,
    newFile?: File | null,
    newUrl?: string | null,
}

export type EditMediaInfoModel = {
    objectId: string,
} & CreateMediaInfoModel
export type DeleteMediaInfoModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    objectId: string
}

export type CreateGenreProportionModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    genreId: string,
    proportion?: number | null,
}
export type EditGenreProportionModel = { } & CreateGenreProportionModel
export type DeleteGenreProportionModel = { } & CreateGenreProportionModel


export type EditDateModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    value?: Date | null,
}

export type VoteEditModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
    ratingPercentage: number,
}

export type VoteDeleteModel = {
    animeTitleId?: string | null,
    animeSeasonId?: string | null,
    animeEpisodeId?: string | null,
}