package main

import (
	"fmt"
)

func main() {
	fmt.Println("oapi-codegen: Generate Go code from OpenAPI specs")
	fmt.Println()
	fmt.Println("This package is a code generator, not a runtime library.")
	fmt.Println("See the examples below for usage patterns.")
}

// oapi-codegen generates Go server and client code from OpenAPI 3.0 specs.
//
// Installation:
//   go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest
//
// Basic usage:
//   oapi-codegen -package api -generate types,server,spec api.yaml > api.gen.go
//
// Generation targets:
//   - types:  Generate type definitions from schemas
//   - server: Generate server interface and handlers
//   - client: Generate HTTP client
//   - spec:   Embed the OpenAPI spec in the binary
//   - skip-prune: Don't remove unused types
//
// Example OpenAPI spec (api.yaml):
/*
openapi: "3.0.0"
info:
  title: Pet Store API
  version: "1.0"
paths:
  /pets:
    get:
      operationId: listPets
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
      responses:
        '200':
          description: List of pets
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
    post:
      operationId: createPet
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewPet'
      responses:
        '201':
          description: Created pet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
  /pets/{petId}:
    get:
      operationId: getPetById
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: A pet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
components:
  schemas:
    Pet:
      type: object
      required: [id, name]
      properties:
        id:
          type: string
        name:
          type: string
        tag:
          type: string
    NewPet:
      type: object
      required: [name]
      properties:
        name:
          type: string
        tag:
          type: string
*/

// Generated server interface looks like:
//
// type ServerInterface interface {
//     ListPets(ctx echo.Context, params ListPetsParams) error
//     CreatePet(ctx echo.Context) error
//     GetPetById(ctx echo.Context, petId string) error
// }

// Implement the interface:
//
// type PetStore struct {
//     pets map[string]Pet
// }
//
// func (s *PetStore) ListPets(ctx echo.Context, params ListPetsParams) error {
//     pets := make([]Pet, 0, len(s.pets))
//     for _, p := range s.pets {
//         pets = append(pets, p)
//     }
//     return ctx.JSON(http.StatusOK, pets)
// }
//
// func (s *PetStore) CreatePet(ctx echo.Context) error {
//     var newPet NewPet
//     if err := ctx.Bind(&newPet); err != nil {
//         return err
//     }
//     pet := Pet{
//         Id:   uuid.NewString(),
//         Name: newPet.Name,
//         Tag:  newPet.Tag,
//     }
//     s.pets[pet.Id] = pet
//     return ctx.JSON(http.StatusCreated, pet)
// }

// Register with Echo:
//
// e := echo.New()
// store := &PetStore{pets: make(map[string]Pet)}
// RegisterHandlers(e, store)
// e.Start(":8080")

// Generated client usage:
//
// client, err := NewClientWithResponses("http://localhost:8080")
// resp, err := client.ListPetsWithResponse(ctx, &ListPetsParams{
//     Limit: ptr(10),
// })
// if resp.JSON200 != nil {
//     for _, pet := range *resp.JSON200 {
//         fmt.Println(pet.Name)
//     }
// }

// Supported server frameworks:
//   - Echo (default)
//   - Chi
//   - Gin
//   - Gorilla Mux
//   - net/http (stdlib)
//   - Fiber
//
// Use -generate flags to select framework:
//   oapi-codegen -generate chi-server ...
//   oapi-codegen -generate gin-server ...
//   oapi-codegen -generate std-http-server ...
