// @bun
var I=Object.defineProperty;var J=(w)=>w;function K(w,A){this[w]=J.bind(null,A)}var P=(w,A)=>{for(var F in A)I(w,F,{get:A[F],enumerable:!0,configurable:!0,set:K.bind(A,F)})};var Q=(w,A)=>()=>(w&&(A=w(w=0)),A);import{schemaValidationTypescriptBrief as E}from"@contractspec/bundle.library/components/docs/intent/intent-pages.docblocks";import{SeoOptimizer as M}from"@contractspec/lib.content-gen/seo";import{CodeBlock as G}from"@contractspec/lib.design-system";import H from"@contractspec/lib.ui-link";import{ChevronRight as N}from"lucide-react";import{jsx as q,jsxs as D}from"react/jsx-runtime";var $=new M().optimize(E);function v(){return D("div",{className:"space-y-8",children:[D("div",{className:"space-y-3",children:[q("h1",{className:"font-bold text-4xl",children:E.title}),q("p",{className:"text-lg text-muted-foreground",children:E.summary})]}),D("div",{className:"card-subtle space-y-4 p-6",children:[q("h2",{className:"font-bold text-2xl",children:"Validation Pain Points"}),q("ul",{className:"space-y-2 text-muted-foreground text-sm",children:E.problems.map((w,A)=>q("li",{children:w},A))})]}),D("div",{className:"card-subtle space-y-4 p-6",children:[q("h2",{className:"font-bold text-2xl",children:"Type-safe Solutions"}),q("ul",{className:"space-y-2 text-muted-foreground text-sm",children:E.solutions.map((w,A)=>q("li",{children:w},A))})]}),D("div",{className:"space-y-6",children:[D("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Contract Schema"}),q("p",{className:"text-muted-foreground text-sm",children:"Define data models with automatic TypeScript generation."}),q(G,{language:"typescript",filename:"src/contracts/user.schema.ts",code:`import { SchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';

export const UserSchema = new SchemaModel({
  type: 'object',
  properties: {
    id: {
      type: 'string',
      format: 'uuid',
      required: true,
      description: 'Unique user identifier',
    },
    email: {
      type: 'string',
      format: 'email',
      required: true,
      description: 'User email address',
    },
    name: {
      type: 'string',
      minLength: 1,
      maxLength: 100,
      required: true,
      description: 'Display name for the user',
    },
    role: {
      type: 'string',
      enum: ['user', 'admin', 'moderator'],
      default: 'user',
      description: 'User role in the system',
    },
    createdAt: {
      type: 'string',
      format: 'date-time',
      required: true,
      description: 'Account creation timestamp',
    },
  },
  required: ['id', 'email', 'name', 'createdAt'],
  metadata: {
    name: 'User',
    description: 'User account information',
  },
});`})]}),D("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Generated Types"}),q("p",{className:"text-muted-foreground text-sm",children:"TypeScript types are automatically generated with proper validation."}),q(G,{language:"typescript",filename:"generated/types/user.ts",code:`// Auto-generated from UserSchema
export interface User {
  id: string;
  email: string;
  name: string;
  role: 'user' | 'admin' | 'moderator';
  createdAt: string;
}

// Auto-generated Zod schema for runtime validation
export const UserSchemaZod = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  name: z.string().min(1).max(100),
  role: z.enum(['user', 'admin', 'moderator']).default('user'),
  createdAt: z.string().datetime(),
});

// Generated validation utilities
export function validateUser(data: unknown): User {
  return UserSchemaZod.parse(data);
}

export function isUser(data: unknown): data is User {
  return UserSchemaZod.safeParse(data).success;
}`})]}),D("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Runtime Validation"}),q("p",{className:"text-muted-foreground text-sm",children:"Use generated validation in your API handlers with zero boilerplate."}),q(G,{language:"typescript",filename:"src/handlers/user-handler.ts",code:`import { validateUser } from '../generated/types/user';

export async function createUserHandler(request: Request) {
  try {
    const input = validateUser(await request.json());
    
    // input is now fully typed as User
    const user = await db.users.create({
      data: {
        ...input,
        createdAt: new Date().toISOString(),
      },
    });
    
    return Response.json({ user });
  } catch (error) {
    if (error instanceof z.ZodError) {
      return Response.json(
        { 
          error: 'Validation failed',
          details: error.errors 
        },
        { status: 400 }
      );
    }
    
    throw error;
  }
}`})]})]}),D("div",{className:"flex items-center gap-4 pt-4",children:[D(H,{href:"/docs/guides/spec-validation-and-typing",className:"btn-primary",children:["Type Safety Guide ",q(N,{size:16})]}),q(H,{href:"/docs/intent/generate-client-from-schema",className:"btn-ghost",children:"Client Generation"})]})]})}export{$ as metadata,v as SchemaValidationTypescriptPage};
