// @bun
import{generateClientFromSchemaBrief as D}from"@contractspec/bundle.library/components/docs/intent/intent-pages.docblocks";import{SeoOptimizer as I}from"@contractspec/lib.content-gen/seo";import{CodeBlock as A}from"@contractspec/lib.design-system";import H from"@contractspec/lib.ui-link";import{ChevronRight as J}from"lucide-react";import{jsx as q,jsxs as w}from"react/jsx-runtime";var T=new I().optimize(D);function U(){return w("div",{className:"space-y-8",children:[w("div",{className:"space-y-3",children:[q("h1",{className:"font-bold text-4xl",children:D.title}),q("p",{className:"text-lg text-muted-foreground",children:D.summary})]}),w("div",{className:"card-subtle space-y-4 p-6",children:[q("h2",{className:"font-bold text-2xl",children:"Client Development Problems"}),q("ul",{className:"space-y-2 text-muted-foreground text-sm",children:D.problems.map((E,G)=>q("li",{children:E},G))})]}),w("div",{className:"card-subtle space-y-4 p-6",children:[q("h2",{className:"font-bold text-2xl",children:"Automated Solutions"}),q("ul",{className:"space-y-2 text-muted-foreground text-sm",children:D.solutions.map((E,G)=>q("li",{children:E},G))})]}),w("div",{className:"space-y-6",children:[w("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Contract Definition"}),q("p",{className:"text-muted-foreground text-sm",children:"Define your API contract once, generate clients for any language."}),q(A,{language:"typescript",filename:"src/contracts/api.contract.ts",code:`import { defineContract } from '@contractspec/lib.contracts-spec';
import { SchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';

export const ApiContract = defineContract({
  name: 'MyAPI',
  version: '1.0.0',
  baseUrl: 'https://api.example.com',
  operations: {
    getUsers: {
      goal: 'Retrieve paginated list of users',
      method: 'GET',
      path: '/users',
      input: new SchemaModel({
        type: 'object',
        properties: {
          page: { type: 'integer', minimum: 1, default: 1 },
          limit: { type: 'integer', minimum: 1, maximum: 100, default: 20 },
        },
      }),
      output: new SchemaModel({
        type: 'object',
        properties: {
          users: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                id: { type: 'string', required: true },
                email: { type: 'string', required: true },
                name: { type: 'string', required: true },
              },
            },
          },
          pagination: {
            type: 'object',
            properties: {
              page: { type: 'integer', required: true },
              limit: { type: 'integer', required: true },
              total: { type: 'integer', required: true },
            },
          },
        },
      }),
    },
    createUser: {
      goal: 'Create a new user account',
      method: 'POST',
      path: '/users',
      input: new SchemaModel({
        type: 'object',
        properties: {
          email: { type: 'string', format: 'email', required: true },
          name: { type: 'string', minLength: 1, required: true },
        },
      }),
      output: new SchemaModel({
        type: 'object',
        properties: {
          id: { type: 'string', required: true },
          email: { type: 'string', required: true },
          name: { type: 'string', required: true },
          createdAt: { type: 'string', format: 'date-time', required: true },
        },
      }),
    },
  },
  metadata: {
    description: 'User management API with authentication',
    tags: ['users', 'authentication'],
  },
});`})]}),w("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Generate Multiple Clients"}),q("p",{className:"text-muted-foreground text-sm",children:"Generate type-safe clients for any language from the same contract."}),q(A,{language:"bash",filename:"generate-clients",code:`# Generate all supported language clients
contractspec generate clients \\
  --contract ./src/contracts/api.contract.ts \\
  --output ./generated/clients \\
  --languages typescript,python,go,java,csharp

# Generate specific language client
contractspec generate clients \\
  --contract ./src/contracts/api.contract.ts \\
  --output ./generated/clients \\
  --languages typescript \\
  --format npm-package

# Options
# --with-types: Include TypeScript definitions
# --with-tests: Generate client test suites
# --with-docs: Include client documentation
# --framework: Use specific HTTP client framework`})]}),w("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Generated Client Examples"}),q("p",{className:"text-muted-foreground text-sm",children:"Each generated client is fully type-safe and idiomatic."}),w("div",{className:"space-y-4",children:[w("div",{className:"card-subtle p-4",children:[q("h4",{className:"font-semibold text-lg",children:"TypeScript Client"}),q(A,{language:"typescript",filename:"generated/clients/typescript/index.ts",code:`import { MyAPIClient } from './client';

const client = new MyAPIClient({
  baseUrl: 'https://api.example.com',
  apiKey: process.env.API_KEY,
});

// Type-safe method calls
const users = await client.getUsers({
  page: 1,
  limit: 10,
});

const newUser = await client.createUser({
  email: 'user@example.com',
  name: 'John Doe',
});

// Full type inference
// users: GetUsersResponse
// newUser: CreateUserResponse`})]}),w("div",{className:"card-subtle p-4",children:[q("h4",{className:"font-semibold text-lg",children:"Python Client"}),q(A,{language:"python",filename:"generated/clients/python/index.py",code:`from myapi_client import MyAPIClient

client = MyAPIClient(
    base_url='https://api.example.com',
    api_key=os.getenv('API_KEY')
)

# Type-safe method calls
users = await client.get_users(
    page=1,
    limit=10
)

new_user = await client.create_user(
    email='user@example.com',
    name='John Doe'
)

# Full type hints
# users: GetUsersResponse
# new_user: CreateUserResponse`})]}),w("div",{className:"card-subtle p-4",children:[q("h4",{className:"font-semibold text-lg",children:"Go Client"}),q(A,{language:"go",filename:"generated/clients/go/client.go",code:`package main

import (
    "context"
    "myapi_client"
)

func main() {
    client := myapi_client.NewMyAPIClient(
        myapi_client.WithBaseURL("https://api.example.com"),
        myapi_client.WithAPIKey(os.Getenv("API_KEY")),
    )
    
    // Type-safe method calls
    users, err := client.GetUsers(&myapi_client.GetUsersParams{
        Page: 1,
        Limit: 10,
    })
    
    newUser, err := client.CreateUser(&myapi_client.CreateUserParams{
        Email: "user@example.com",
        Name:  "John Doe",
    })
    
    // Full type checking at compile time
    // users: *GetUsersResponse
    // newUser: *CreateUserResponse
}`})]})]})]}),w("div",{className:"space-y-3",children:[q("h2",{className:"font-bold text-2xl",children:"Advanced Features"}),q("p",{className:"text-muted-foreground text-sm",children:"Generated clients include enterprise-grade features out of the box."}),q(A,{language:"typescript",filename:"client-features.ts",code:`// Advanced client features
const client = new MyAPIClient({
  baseUrl: 'https://api.example.com',
  apiKey: 'your-api-key',
  
  // Retry configuration
  retryConfig: {
    maxRetries: 3,
    backoffMultiplier: 2,
    maxDelay: 30000,
  },
  
  // Request/Response interceptors
  interceptors: {
    request: [(config) => {
      // Add authentication headers
      config.headers.Authorization = \`Bearer \${await getAuthToken()}\`;
      return config;
    }],
    response: [(response) => {
      // Log API calls
      console.log(\`API Call: \${response.config.method} \${response.config.url}\`);
      return response;
    }],
  },
  
  // Error handling
  errorHandler: (error) => {
    if (error.status === 401) {
      // Refresh token and retry
      return refreshTokenAndRetry(error.originalRequest);
    }
    throw error;
  },
});

// Automatic request deduplication
const user1 = client.getUser({ id: '123' });
const user2 = client.getUser({ id: '123' }); // Uses cached result

// Request cancellation
const controller = new AbortController();
const promise = client.getUsers({ page: 1, signal: controller.signal });
controller.abort(); // Cancels the request`})]})]}),w("div",{className:"flex items-center gap-4 pt-4",children:[w(H,{href:"/docs/guides/generate-docs-clients-schemas",className:"btn-primary",children:["Client Generation Guide ",q(J,{size:16})]}),q(H,{href:"/docs/intent/contract-first-api",className:"btn-ghost",children:"Contract-first API"})]})]})}export{T as metadata,U as GenerateClientFromSchemaPage};
