/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2023 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import {z} from "zod";
import {PlayerSchema} from "./data.ts";

export const SchematicSchema = z.object({
    name: z.string(),
    id: z.number(),
    type: z.string().nullable(),
    owner: z.number(),
    item: z.string(),
    lastUpdate: z.number().positive(),
    rank: z.number(),
    replaceColor: z.boolean(),
    allowReplay: z.boolean(),
});

export type Schematic = z.infer<typeof SchematicSchema>

export const SchematicListSchema = z.object({
    breadcrumbs: z.array(z.object({
        name: z.string(),
        id: z.number(),
    })),
    schematics: z.array(SchematicSchema),
    players: z.record(z.string(), PlayerSchema),
});

export type SchematicList = z.infer<typeof SchematicListSchema>

export const SchematicInfoSchema = z.object({
    members: z.array(PlayerSchema),
    path: z.string(),
    schem: SchematicSchema,
});

export type SchematicInfo = z.infer<typeof SchematicInfoSchema>

export const SchematicCodeSchema = z.object({
    id: z.number().gte(0),
    code: z.string(),
    expires: z.number().positive(),
});

export type SchematicCode = z.infer<typeof SchematicCodeSchema>