import * as z from "zod";
import { DevelopmentLanguageTypeEnum } from "./types";

export const searchFormSchema = z.object({
    appCode: z.string().optional(),
    appName: z.string().optional(),
    language: z.nativeEnum(DevelopmentLanguageTypeEnum).optional(),
    enabled: z.boolean().optional(),
});

export const applicationFormSchema = z.object({
    appCode: z.string().min(1, '应用编码不能为空'),
    appName: z.string().min(1, '应用名称不能为空'),
    appDesc: z.string().max(200, "应用描述不能超过200个字符").optional(),
    externalSystemId: z.number({
        required_error: '请选择Git实例',
        invalid_type_error: 'Git实例必须是数字',
    }),
    projectGroupId: z.number().min(1, "请选择项目组"),
    repoGroupId: z.number({
        required_error: '请选择代码仓库组',
        invalid_type_error: '代码仓库组必须是数字',
    }),
    repoProjectId: z.number({
        required_error: '请选择项目',
        invalid_type_error: '项目必须是数字',
    }),
    language: z.nativeEnum(DevelopmentLanguageTypeEnum, {
        required_error: "请选择开发语言",
    }),
    enabled: z.boolean().default(true),
    sort: z.number().min(0).default(0),
});

export type SearchFormValues = z.infer<typeof searchFormSchema>;
export type ApplicationFormValues = z.infer<typeof applicationFormSchema>;