openapi: 3.0.1
info:
  title: Evolution Foundation - Auth Service - Accounts
  description: Authentication and user and account management
  version: v1.0.0
servers:
- url: https://api.evoai.app
  description: Production server
- url: http://localhost:3001
  description: Development server
  variables:
    port:
      default: '3001'
- url: '{customUrl}'
  description: Custom server
  variables:
    customUrl:
      default: https://your-instance.com
      description: Enter your server URL
paths:
  /api/v1/accounts:
    post:
      summary: Create account
      description: Create a new account with initial user
      operationId: createAccount
      security:
      - ApiAccessTokenAuth: []
      responses:
        '201':
          description: Account created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      user:
                        $ref: '#/components/schemas/User'
                      account:
                        $ref: '#/components/schemas/Account'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Account created successfully
              example:
                success: true
                data:
                  user:
                    id: 660e8400-e29b-41d4-a716-446655440001
                    name: John Doe
                    email: john@acme.com
                    type: User
                    confirmed: true
                  account:
                    id: 550e8400-e29b-41d4-a716-446655440000
                    name: Acme Corporation
                    domain: acme
                    support_email: support@acme.com
                    locale: en
                    status: active
                    created_at: '2024-01-01T00:00:00Z'
                    updated_at: '2024-01-01T00:00:00Z'
                meta:
                  timestamp: '2024-01-01T00:00:00Z'
                message: Account created successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Signup disabled or resource not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Signup is disabled
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
        '422':
          description: Unprocessable Entity (validation errors)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation errors
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Validation failed
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts
                      method: POST
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                account_name:
                  type: string
                user_full_name:
                  type: string
                email:
                  type: string
                  format: email
                password:
                  type: string
                  minLength: 8
                locale:
                  type: string
                  default: en
                support_email:
                  type: string
                  format: email
              required:
              - account_name
              - user_full_name
              - email
              - password
  /api/v1/accounts/{id}:
    parameters:
    - name: id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get account details
      description: Retrieve detailed information about a specific account
      operationId: getAccount
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Account details retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/Account'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Account retrieved successfully
              example:
                success: true
                data:
                  id: 550e8400-e29b-41d4-a716-446655440000
                  name: Acme Corporation
                  domain: acme
                  support_email: support@acme.com
                  locale: en
                  status: active
                  settings:
                    auto_resolve_after: 24
                    audio_transcriptions: true
                  custom_attributes:
                    industry: Technology
                    company_size: 50-100
                  created_at: '2024-01-01T00:00:00Z'
                  updated_at: '2024-01-15T10:30:00Z'
                  role: administrator
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Account retrieved successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: GET
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: GET
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: GET
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: GET
    patch:
      summary: Update account
      description: Update account information
      operationId: updateAccount
      security:
      - ApiAccessTokenAuth: []
      parameters: []
      responses:
        '200':
          description: Account updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      account:
                        $ref: '#/components/schemas/Account'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Account updated successfully
              example:
                success: true
                data:
                  account:
                    id: 550e8400-e29b-41d4-a716-446655440000
                    name: Acme Corporation Updated
                    domain: acme
                    support_email: support@acme.com
                    locale: en
                    status: active
                    settings:
                      auto_resolve_after: 24
                      audio_transcriptions: true
                    custom_attributes:
                      industry: Technology
                      company_size: 50-100
                    created_at: '2024-01-01T00:00:00Z'
                    updated_at: '2024-01-15T10:30:00Z'
                    role: administrator
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Account updated successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
        '422':
          description: Unprocessable Entity (validation errors)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation errors
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Validation failed
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}
                      method: PATCH
                validation_error:
                  summary: Validation failed
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Validation failed
                      details:
                      - field: name
                        messages:
                        - can't be blank
                        full_messages:
                        - Name can't be blank
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/super_admin/accounts/550e8400-e29b-41d4-a716-446655440000
                      method: PATCH
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Account name
                locale:
                  type: string
                  description: Account locale
                  example: en
                timezone:
                  type: string
                  description: Account timezone
                  example: UTC
                domain:
                  type: string
                  description: Custom domain
                support_email:
                  type: string
                  format: email
                  description: Support email address
                custom_attributes:
                  type: object
                  description: Custom account attributes
                  additionalProperties: true
  /api/v1/accounts/{id}/active_plan:
    parameters:
    - name: id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get account active plan
      description: Get active plan for specific account
      operationId: getAccountActivePlan
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Active plan retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/ActivePlan'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Active plan retrieved successfully
              example:
                success: true
                data:
                  id: 770e8400-e29b-41d4-a716-446655440002
                  plan_id: 880e8400-e29b-41d4-a716-446655440003
                  plan_name: Professional
                  plan_description: Professional plan with advanced features
                  is_active: true
                  is_custom: false
                  starts_at: '2024-01-01T00:00:00Z'
                  ends_at: null
                  used_plan: false
                  features:
                    conversations: 10000
                    storage_gb: 100
                  created_at: '2024-01-01T00:00:00Z'
                  updated_at: '2024-01-01T00:00:00Z'
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Active plan retrieved successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/active_plan
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/active_plan
                      method: GET
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/active_plan
                      method: GET
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/active_plan
                      method: GET
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/active_plan
                      method: GET
  /api/v1/accounts/{id}/cache_keys:
    parameters:
    - name: id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get account cache keys
      description: Retrieve cache keys associated with the account
      operationId: getAccountCacheKeys
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Cache keys retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      type: string
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Cache keys retrieved successfully
              example:
                success: true
                data:
                - account:550e8400-e29b-41d4-a716-446655440000:settings
                - account:550e8400-e29b-41d4-a716-446655440000:features
                - account:550e8400-e29b-41d4-a716-446655440000:plan
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Cache keys retrieved successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/cache_keys
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/cache_keys
                      method: GET
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/cache_keys
                      method: GET
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/cache_keys
                      method: GET
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/cache_keys
                      method: GET
  /api/v1/accounts/{id}/permissions:
    parameters:
    - name: id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get account permissions
      description: Get permissions for current user in this account
      operationId: getAccountPermissions
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Permissions retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      permissions:
                        type: array
                        items:
                          type: string
                      role:
                        type: object
                        nullable: true
                        properties:
                          id:
                            type: string
                            format: uuid
                          key:
                            type: string
                          name:
                            type: string
                      is_super_admin:
                        type: boolean
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Account permissions retrieved successfully
              example:
                success: true
                data:
                  permissions:
                  - accounts.read
                  - accounts.update
                  - users.read
                  role:
                    id: 770e8400-e29b-41d4-a716-446655440002
                    key: administrator
                    name: Administrator
                  is_super_admin: false
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Account permissions retrieved successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/permissions
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/permissions
                      method: GET
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/permissions
                      method: GET
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/permissions
                      method: GET
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/permissions
                      method: GET
  /api/v1/accounts/{id}/update_active_at:
    parameters:
    - name: id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    post:
      summary: Update account last activity
      description: Update the last activity timestamp for the account
      operationId: updateAccountActivity
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Activity updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      active_at:
                        type: string
                        format: date-time
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Account active timestamp updated successfully
              example:
                success: true
                data:
                  active_at: '2024-01-15T10:30:00Z'
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Account active timestamp updated successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/update_active_at
                      method: PATCH
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/update_active_at
                      method: PATCH
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/update_active_at
                      method: PATCH
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/update_active_at
                      method: PATCH
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/accounts/{id}/update_active_at
                      method: PATCH
  /api/v1/active_plan:
    get:
      summary: Get active plan
      description: Get active plan for current account (uses account-id header)
      operationId: getActivePlan
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: account-id
        in: header
        description: Account ID
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Active plan retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/ActivePlan'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        example: '2024-01-01T00:00:00Z'
                  message:
                    type: string
                    example: Active plan retrieved successfully
              example:
                success: true
                data:
                  id: 770e8400-e29b-41d4-a716-446655440002
                  plan_id: 880e8400-e29b-41d4-a716-446655440003
                  plan_name: Professional
                  plan_description: Professional plan with advanced features
                  is_active: true
                  is_custom: false
                  starts_at: '2024-01-01T00:00:00Z'
                  ends_at: null
                  used_plan: false
                  features:
                    conversations: 10000
                    storage_gb: 100
                  created_at: '2024-01-01T00:00:00Z'
                  updated_at: '2024-01-01T00:00:00Z'
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Active plan retrieved successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_request:
                  summary: Invalid request parameters
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Invalid request parameters
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/active_plan
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: Unauthorized access
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/active_plan
                      method: GET
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    success: false
                    error:
                      code: FORBIDDEN
                      message: You do not have permission to access this resource
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/active_plan
                      method: GET
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_found:
                  summary: Account not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Account not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/active_plan
                      method: GET
        '500':
          description: Internal Server Error (server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    success: false
                    error:
                      code: INTERNAL_ERROR
                      message: An unexpected error occurred
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/active_plan
                      method: GET
components:
  schemas:
    Account:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Account unique identifier
        name:
          type: string
          description: Account name
        domain:
          type: string
          nullable: true
          description: Account custom domain
        support_email:
          type: string
          format: email
          nullable: true
          description: Support email address
        locale:
          type: string
          enum:
          - en
          - pt
          - pt_BR
          - es
          - fr
          - de
          description: Account locale
        status:
          type: string
          enum:
          - active
          - suspended
          description: Account status
        settings:
          type: object
          additionalProperties: true
          description: Account settings
        custom_attributes:
          type: object
          additionalProperties: true
          description: Custom account attributes
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        role:
          type: string
          description: User role in this account
    ActivePlan:
      type: object
      properties:
        id:
          type: string
          format: uuid
        plan_id:
          type: string
          format: uuid
        plan_name:
          type: string
        plan_description:
          type: string
          nullable: true
        is_active:
          type: boolean
        is_custom:
          type: boolean
        starts_at:
          type: string
          format: date-time
          nullable: true
        ends_at:
          type: string
          format: date-time
          nullable: true
        used_plan:
          type: boolean
        features:
          type: object
          additionalProperties: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      required:
      - success
      - error
      - meta
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          required:
          - code
          - message
          properties:
            code:
              type: string
              example: VALIDATION_ERROR
            message:
              type: string
              example: Validation failed
            details:
              type: object
              additionalProperties: true
              nullable: true
        meta:
          type: object
          required:
          - timestamp
          - path
          - method
          properties:
            timestamp:
              type: string
              format: date-time
              example: '2024-01-15T10:30:00Z'
            path:
              type: string
              example: /api/v1/super_admin/accounts/123
            method:
              type: string
              example: POST
    User:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        email:
          type: string
          format: email
        type:
          type: string
          enum:
          - User
          - SuperAdmin
        role:
          type: object
          nullable: true
          properties:
            id:
              type: string
              format: uuid
            key:
              type: string
            name:
              type: string
        pubsub_token:
          type: string
        display_name:
          type: string
          nullable: true
        availability:
          type: string
          enum:
          - online
          - busy
          - offline
        mfa_enabled:
          type: boolean
        confirmed:
          type: boolean
        custom_attributes:
          type: object
          additionalProperties: true
        ui_settings:
          type: object
          additionalProperties: true
        is_super_admin:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
  securitySchemes:
    DeviseTokenAuth:
      type: apiKey
      in: header
      name: access-token
      description: Devise Token Auth - requires access-token, client, and uid headers
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    SuperAdminAuth:
      type: apiKey
      in: header
      name: api_access_token
      description: Super Admin authentication token
    ApiAccessTokenAuth:
      type: apiKey
      in: header
      name: api_access_token
      description: API access token authentication
