import * as z from 'zod';
import { ROLE_ASSIGNMENT_SCOPE_MODES } from '@/lib/auth/rbac';
export const userSchema = z.object({
  name: z.string().min(2, 'Name must be at least 2 characters'),
  email: z.string().email('Please enter a valid email'),
  password: z.string().optional(),
  systemRole: z.enum(['super_admin', 'user']),
  memberships: z
    .array(
      z.object({
        organizationId: z.string().min(1),
        membershipRole: z.enum(['admin', 'user'])
      })
    )
    .min(1, 'Select at least one organization'),
  crmRoleAssignments: z.array(
    z.object({
      id: z.string().optional(),
      organizationId: z.string().min(1),
      roleProfileId: z.string().min(1),
      branchScopeMode: z.enum(ROLE_ASSIGNMENT_SCOPE_MODES),
      branchScopeIds: z.array(z.string()),
      productTypeScopeMode: z.enum(ROLE_ASSIGNMENT_SCOPE_MODES),
      productTypeScopeIds: z.array(z.string()),
      isPrimary: z.boolean(),
      isActive: z.boolean()
    })
  )
});

export type UserFormValues = z.infer<typeof userSchema>;
