import { z } from "zod";
import { LanguageTypes } from "@/validations/mutual/language/validations";
import { buildingPartsFieldsTr } from "@/languages/custom/building/turkish";
import { buildingPartsFieldsEn } from "@/languages/custom/building/english";

interface BasicInterface {
    uuid: string;
    firstName: string;
    lastName: string;
    email: string;
    phoneNumber: string;
    country: string;
    description: string;
    isDeleted: boolean;
    isConfirmed: boolean;
    createdAt: string;
    updatedAt: string;
}

const labelTranslations = {
    tr: buildingPartsFieldsTr,
    en: buildingPartsFieldsEn,
};

const errorMessagesTr = {
    firstName: "Ad alanı zorunludur",
    lastName: "Soyad alanı zorunludur",
    email: "E-posta alanı zorunludur",
    phoneNumber: "Telefon numarası alanı zorunludur",
    country: "Ülke alanı zorunludur",
};

const errorMessagesEn = {
    firstName: "First name is required",
    lastName: "Last name is required",
    email: "Email is required",
    phoneNumber: "Phone number is required",
    country: "Country is required",
};

const errorMessages = {
    tr: errorMessagesTr,
    en: errorMessagesEn,
};

function getSchemaByLanguage(lang: LanguageTypes) {
    const createSchema = z.object({
        "Users.firstName": z
            .string()
            .min(1, errorMessages[lang].firstName)
            .describe("text"),
        "Users.lastName": z
            .string()
            .min(1, errorMessages[lang].lastName)
            .describe("text"),
        "Users.email": z
            .string()
            .email(errorMessages[lang].email)
            .describe("email"),
        "Users.phoneNumber": z
            .string()
            .min(12, errorMessages[lang].phoneNumber)
            .describe("phone"),
        "Users.country": z
            .string()
            .min(1, errorMessages[lang].country)
            .optional()
            .describe("selection:country"),
        "Users.description": z.string().optional().describe("text"),
        "Users.isDeleted": z.boolean().optional().describe("checkbox"),
        "Users.isConfirmed": z.boolean().optional().describe("checkbox"),
    });

    const updateSchema = z.object({
        "Users.firstName": z
            .string()
            .min(1, errorMessages[lang].firstName)
            .describe("text"),
        "Users.lastName": z
            .string()
            .min(1, errorMessages[lang].lastName)
            .describe("text"),
        "Users.email": z
            .string()
            .email(errorMessages[lang].email)
            .describe("email"),
        "Users.phoneNumber": z
            .string()
            .min(12, errorMessages[lang].phoneNumber)
            .describe("phone"),
        "Users.country": z
            .string()
            .min(1, errorMessages[lang].country)
            .optional()
            .describe("selection:country"),
        "Users.description": z.string().optional().describe("text"),
        "Users.isDeleted": z.boolean().optional().describe("checkbox"),
        "Users.isConfirmed": z.boolean().optional().describe("checkbox"),
    });

    const detailSchema = z.object({
        "Users.uuid": z.string(),
        "Users.firstName": z.string(),
        "Users.lastName": z.string(),
        "Users.email": z.string(),
        "Users.phoneNumber": z.string(),
        "Users.country": z.string(),
        "Users.description": z.string().optional(),
        "Users.isDeleted": z.boolean(),
        "Users.isConfirmed": z.boolean(),
        "Users.createdAt": z.string(),
        "Users.updatedAt": z.string(),
    });

    const shortSchema = z.object({
        "Users.uuid": z.string(),
        "Users.firstName": z.string(),
        "Users.lastName": z.string(),
        "Users.email": z.string(),
    });

    const columns = Object.keys(detailSchema.shape);
    const shortColumns = Object.keys(shortSchema.shape);

    const setColumns = columns.map((column) => {
        return labelTranslations[lang][
            column as keyof (typeof labelTranslations)[typeof lang]
        ];
    });
    const setShortColumns = shortColumns.map((column) => {
        return labelTranslations[lang][
            column as keyof (typeof labelTranslations)[typeof lang]
        ];
    });
    return {
        createSchema,
        updateSchema,
        detailSchema,
        shortSchema,
        labels: labelTranslations[lang],
        columns: setColumns,
        shortColumns: setShortColumns,
    };
}

export { getSchemaByLanguage };
