import { z } from "zod";

import { createRefinableSchema } from "../../utility-types/create-refinable-schema.js";

import type { ITranslationProperties } from "./translation-properties.js";
import type { CreateContractContext, InferSchemaFromRefinableSchema } from "../../webserver/contract.js";

const createTranslatablePropertiesSchema = createRefinableSchema({
    schema: (context: CreateContractContext) =>
        z.object({
            id: z.string(),
            language: z.string(),
        }),
});

/**
 * Minimum/obligatory properties needed for a translation.
 */
interface ITranslatableProperties extends InferSchemaFromRefinableSchema<typeof createTranslatablePropertiesSchema> {}

/**
 * Information about translation status including details about optional, required and base value fields.
 */
interface ITranslationStatus extends ITranslationProperties {
    language: string;
    isTranslationComplete?: boolean;
    isTranslationCompleteRecursive?: boolean;
    baseValueFields?: string[];
    machineTranslationStatus?: EMachineTranslationStatus;
}

enum EMachineTranslationStatus {
    NoTranslation = "no-translation",
    Full = "full",
    Partly = "partly",
}

export {
    createTranslatablePropertiesSchema,
    EMachineTranslationStatus,
    type ITranslatableProperties,
    type ITranslationStatus,
};
