openapi: 3.0.3
info:
  title: Sample User API
  description: A sample API for user management
  version: 1.0.0

servers:
  - url: http://localhost:8000/api/v1

paths:
  /users:
    get:
      operationId: listUsers
      summary: List all users
      description: Retrieve a list of all users in the system
      parameters:
        - name: active_only
          in: query
          description: Filter to only active users
          required: false
          schema:
            type: boolean
            default: false
        - name: limit
          in: query
          description: Maximum number of users to return
          required: false
          schema:
            type: integer
            default: 100
      responses:
        '200':
          description: List of users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
    post:
      operationId: createUser
      summary: Create a new user
      description: Create a new user account
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserRequest'
      responses:
        '201':
          description: User created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /users/{userId}:
    get:
      operationId: getUser
      summary: Get user by ID
      description: Retrieve a specific user by their ID
      parameters:
        - name: userId
          in: path
          required: true
          description: User ID
          schema:
            type: integer
      responses:
        '200':
          description: User details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    put:
      operationId: updateUser
      summary: Update user
      description: Update an existing user's information
      parameters:
        - name: userId
          in: path
          required: true
          description: User ID
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateUserRequest'
      responses:
        '200':
          description: User updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
        '400':
          description: Validation error
        '404':
          description: User not found
    delete:
      operationId: deleteUser
      summary: Delete user
      description: Delete a user from the system
      parameters:
        - name: userId
          in: path
          required: true
          description: User ID
          schema:
            type: integer
      responses:
        '204':
          description: User deleted successfully
        '404':
          description: User not found

  /users/{userId}/deactivate:
    post:
      operationId: deactivateUser
      summary: Deactivate user
      description: Deactivate a user account
      parameters:
        - name: userId
          in: path
          required: true
          description: User ID
          schema:
            type: integer
      responses:
        '200':
          description: User deactivated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
        '404':
          description: User not found

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          description: User ID
        username:
          type: string
          description: Username
        email:
          type: string
          format: email
          description: Email address
        created_at:
          type: string
          format: date-time
          description: Account creation timestamp
        is_active:
          type: boolean
          description: Whether the user is active
      required:
        - id
        - username
        - email

    CreateUserRequest:
      type: object
      properties:
        username:
          type: string
          minLength: 3
          maxLength: 50
          description: Username (3-50 characters, alphanumeric and underscore only)
        email:
          type: string
          format: email
          description: Email address
      required:
        - username
        - email

    UpdateUserRequest:
      type: object
      properties:
        username:
          type: string
          minLength: 3
          maxLength: 50
          description: New username
        email:
          type: string
          format: email
          description: New email address

    Error:
      type: object
      properties:
        code:
          type: string
          description: Error code
        message:
          type: string
          description: Error message
      required:
        - code
        - message
