// validations/studentValidation.ts
import { z } from 'zod';

// Base schema with common fields
const BaseStudentSchema = z.object({
    name: z.string()
        .min(2, 'Name must be at least 2 characters')
        .max(100, 'Name must be less than 100 characters'),
    
    passportNumber: z.string()
        .min(5, 'Passport number must be at least 5 characters')
        .max(20, 'Passport number must be less than 20 characters'),
    
    course: z.string()
        .min(2, 'Course must be at least 2 characters')
        .max(100, 'Course must be less than 100 characters'),
    
    country: z.string()
        .min(2, 'Country must be at least 2 characters')
        .max(50, 'Country must be less than 50 characters'),
    
    files: z.object({
        passport: z.string().min(1, 'Passport copy is required'),
        photo: z.string().min(1, 'Passport photo is required'),
        educationalDegree: z.string().min(1, 'Educational degree is required'),
        educationalCertificate: z.string().min(1, 'Educational certificate is required'),
        recommendationLetter: z.string().optional(),
        studyPlan: z.string().optional(),
        ieltsOrEnglishProficiency: z.string().optional(),
    })
});

// Create schema (with all required fields)
export const CreateStudentFormSchema = BaseStudentSchema.extend({
    email: z.string()
        .email('Invalid email address')
        .max(100, 'Email must be less than 100 characters'),
    
    phone: z.string()
        .min(10, 'Phone number must be at least 10 digits')
        .max(20, 'Phone number must be less than 20 digits'),
    
    dateOfBirth: z.string()
        .min(1, 'Date of birth is required')
        .refine((date) => {
            const parsedDate = new Date(date);
            return !isNaN(parsedDate.getTime());
        }, 'Invalid date format'),
    
    nationality: z.string()
        .min(2, 'Nationality must be at least 2 characters')
        .max(50, 'Nationality must be less than 50 characters'),
    
    university: z.string()
        .max(100, 'University must be less than 100 characters')
        .optional(),
});

// Edit schema (only fields that can be edited)
export const EditStudentFormSchema = BaseStudentSchema.extend({
    // Only include fields that should be editable
    // Email, phone, dateOfBirth, nationality are not in edit form
});

export type CreateStudentFormData = z.infer<typeof CreateStudentFormSchema>;
export type EditStudentFormData = z.infer<typeof EditStudentFormSchema>;