import type {
    AudioMultipleChoiceQuestion,
    AudioQuestion,
    FullWall,
    ImageMultipleChoiceQuestion,
    ImageQuestion,
    MultipleChoiceQuestion,
    SimpleQuestion
} from "./games/games";

export type VisitedQuestions = number[][];

export type Directory = {
    name: string;
    isDir: true;
};

export type Ressource = {
    _id: string;
    fullpath: string;
    path: string;
    user: string;
    mimetype: string;
    name: string;
    filename: string;
};

export function isDir(dir: Directory | Ressource): dir is Directory {
    return (dir as Directory).isDir === true;
}

export function isRessource(ressource: Ressource | Directory): ressource is Ressource {
    return (ressource as Directory).isDir === undefined;
}

export type _id = string;

export type GameId = _id;

export type Game = {
    name: string;
    owner: _id;
    _id: GameId;
    walls: WallId[];
};

export type WallId = _id;

export type Wall = {
    _id: WallId;
    name: string;
    owner: _id;
    categories: CategoryId[];
};

export function isWall(wall: Wall | FullWall): wall is Wall {
    return (wall as Wall)._id !== undefined;
}

export function isFullWall(wall: Wall | FullWall): wall is FullWall {
    return !Object.hasOwn(wall, "_id");
}

export type CategoryId = _id;

export type Category = {
    _id: CategoryId;
    name: string;
    owner: _id;
    questions: { _id: QuestionId; points: number }[];
};

export type QuestionId = _id;

export type GeneralQuestion =
    | SimpleQuestion
    | MultipleChoiceQuestion
    | ImageQuestion
    | ImageMultipleChoiceQuestion
    | AudioQuestion
    | AudioMultipleChoiceQuestion;
