openapi: 3.0.1
info:
  title: Evolution Foundation - Auth Service - Custom Roles
  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/custom_roles:
    get:
      summary: List custom roles (account-scoped)
      description: List custom roles for current account (uses account-id header)
      operationId: listAccountScopedCustomRoles
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: account-id
        in: header
        description: Account ID
        schema:
          type: string
          format: uuid
      - name: page
        in: query
        schema:
          type: string
          format: uuid
      - name: per_page
        in: query
        schema:
          type: integer
      - name: active
        in: query
        schema:
          type: boolean
      responses:
        '200':
          description: Custom roles retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CustomRole'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                      pagination:
                        type: object
                        properties:
                          page:
                            type: integer
                          pageSize:
                            type: integer
                          total:
                            type: integer
                          totalPages:
                            type: integer
                          hasNextPage:
                            type: boolean
                          hasPreviousPage:
                            type: boolean
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles
                      method: GET
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles
                      method: GET
    post:
      summary: Create custom role
      description: Create a new custom role for current account (uses account-id header)
      operationId: createCustomRole
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: account-id
        in: header
        description: Account ID
        schema:
          type: string
          format: uuid
      responses:
        '201':
          description: Custom role created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      custom_role:
                        $ref: '#/components/schemas/CustomRole'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles
                      method: POST
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles
                      method: POST
        '422':
          description: Unprocessable Entity (validation error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation failed
                  value:
                    success: false
                    error:
                      code: OPERATION_FAILED
                      message: Validation failed
                      details:
                      - Name is required
                      - Key is invalid
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles
                      method: POST
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles
                      method: POST
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                custom_role:
                  type: object
                  properties:
                    key:
                      type: string
                    name:
                      type: string
                    description:
                      type: string
                    is_active:
                      type: boolean
                      default: true
                permissions:
                  type: array
                  items:
                    type: object
                    properties:
                      permission_key:
                        type: string
                  required:
                  - permission_key
              required:
              - custom_role
  /api/v1/custom_roles/available_permissions:
    get:
      summary: Get available permissions (account-scoped)
      description: Get available permissions for custom roles (uses account-id header)
      operationId: getAccountScopedAvailablePermissions
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: account-id
        in: header
        description: Account ID
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Available permissions retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      available_permissions:
                        type: array
                        items:
                          type: string
                      resources:
                        type: object
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/available_permissions
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/available_permissions
                      method: GET
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/available_permissions
                      method: GET
  /api/v1/custom_roles/{id}:
    parameters:
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get custom role
      description: Get details of a custom role
      operationId: getCustomRole
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Custom role retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      custom_role:
                        $ref: '#/components/schemas/CustomRole'
                      permissions:
                        type: array
                        items:
                          type: string
                      permissions_by_resource:
                        type: object
                      resource_scopes:
                        type: array
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: GET
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: GET
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}
                      method: GET
    patch:
      summary: Update custom role
      description: Update a custom role
      operationId: updateCustomRole
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Custom role updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      custom_role:
                        $ref: '#/components/schemas/CustomRole'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: PATCH
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: PATCH
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: PATCH
        '422':
          description: Unprocessable Entity (validation error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation failed
                  value:
                    success: false
                    error:
                      code: OPERATION_FAILED
                      message: Validation failed
                      details:
                      - Name is required
                      - Key is invalid
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: PATCH
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}
                      method: PATCH
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                custom_role:
                  type: object
                  properties:
                    key:
                      type: string
                    name:
                      type: string
                    description:
                      type: string
                    is_active:
                      type: boolean
                permissions:
                  type: array
                  items:
                    type: string
                resource_scopes:
                  type: array
                  items:
                    type: object
    delete:
      summary: Delete custom role
      description: Delete a custom role
      operationId: deleteCustomRole
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Custom role deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
              example:
                success: true
                data: {}
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Custom role deleted successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: DELETE
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: DELETE
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: DELETE
        '422':
          description: Unprocessable Entity (não é possível deletar)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                cannot_delete_with_users:
                  summary: Cannot delete custom role with assigned users
                  value:
                    success: false
                    error:
                      code: OPERATION_FAILED
                      message: Cannot delete custom role with assigned users
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: DELETE
                operation_failed:
                  summary: Failed to delete custom role
                  value:
                    success: false
                    error:
                      code: OPERATION_FAILED
                      message: Failed to delete custom role
                      details:
                      - Error details
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}
                      method: DELETE
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}
                      method: DELETE
  /api/v1/custom_roles/{id}/add_permission:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    post:
      summary: Add permission to custom role
      description: Add a permission to a custom role
      operationId: addPermissionToCustomRole
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Permission added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      permissions:
                        type: array
                        items:
                          type: string
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Permission key is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Permission key is required
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_permission
                      method: POST
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_permission
                      method: POST
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_permission
                      method: POST
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_permission
                      method: POST
        '422':
          description: Unprocessable Entity (invalid permission key)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_permission_key:
                  summary: Invalid permission key
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Failed to add permission. Invalid permission key.
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_permission
                      method: POST
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/add_permission
                      method: POST
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                permission_key:
                  type: string
              required:
              - permission_key
  /api/v1/custom_roles/{id}/add_resource_scope:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    post:
      summary: Add resource scope
      description: Add a resource scope to a custom role
      operationId: addResourceScope
      security:
      - ApiAccessTokenAuth: []
      responses:
        '201':
          description: Resource scope added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      resource_scope:
                        type: object
                      resource_scopes:
                        type: array
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Resource type and resource ID are required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Resource type and resource ID are required
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_resource_scope
                      method: POST
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_resource_scope
                      method: POST
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_resource_scope
                      method: POST
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_resource_scope
                      method: POST
        '422':
          description: Unprocessable Entity (validation error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation failed
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Validation failed
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/add_resource_scope
                      method: POST
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/add_resource_scope
                      method: POST
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                resource_type:
                  type: string
                resource_id:
                  type: string
                  format: uuid
                actions:
                  type: array
                  items:
                    type: string
                  default:
                  - read
              required:
              - resource_type
              - resource_id
  /api/v1/custom_roles/{id}/remove_permission:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    delete:
      summary: Remove permission from custom role
      description: Remove a permission from a custom role
      operationId: removePermissionFromCustomRole
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: permission_key
        in: query
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Permission removed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      permissions:
                        type: array
                        items:
                          type: string
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Permission key is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Permission key is required
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_permission
                      method: DELETE
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_permission
                      method: DELETE
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_permission
                      method: DELETE
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_permission
                      method: DELETE
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/remove_permission
                      method: DELETE
  /api/v1/custom_roles/{id}/remove_resource_scope:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    delete:
      summary: Remove resource scope
      description: Remove a resource scope from a custom role
      operationId: removeResourceScope
      security:
      - ApiAccessTokenAuth: []
      parameters:
      - name: resource_type
        in: query
        required: true
        schema:
          type: string
      - name: resource_id
        in: query
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Resource scope removed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      resource_scopes:
                        type: array
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Resource type and resource ID are required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Resource type and resource ID are required
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_resource_scope
                      method: DELETE
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_resource_scope
                      method: DELETE
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_resource_scope
                      method: DELETE
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/remove_resource_scope
                      method: DELETE
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/remove_resource_scope
                      method: DELETE
  /api/v1/custom_roles/{id}/resource_scopes:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    get:
      summary: Get resource scopes
      description: Get resource scopes for a custom role
      operationId: getResourceScopes
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Resource scopes retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      resource_scopes:
                        type: array
                      scopes_by_type:
                        type: object
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/resource_scopes
                      method: GET
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/resource_scopes
                      method: GET
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/resource_scopes
                      method: GET
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/resource_scopes
                      method: GET
  /api/v1/custom_roles/{id}/update_permissions:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    put:
      summary: Update custom role permissions
      description: Replace all permissions for a custom role
      operationId: updateCustomRolePermissions
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Permissions updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      permissions:
                        type: array
                        items:
                          type: string
                      permissions_by_resource:
                        type: object
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_permissions
                      method: PUT
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_permissions
                      method: PUT
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_permissions
                      method: PUT
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/update_permissions
                      method: PUT
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                permissions:
                  type: array
                  items:
                    type: string
              required:
              - permissions
  /api/v1/custom_roles/{id}/update_resource_scopes:
    parameters:
    - name: account_id
      in: path
      description: Account ID
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      description: Custom Role ID
      required: true
      schema:
        type: string
        format: uuid
    put:
      summary: Update resource scopes
      description: Replace all resource scopes for a custom role
      operationId: updateResourceScopes
      security:
      - ApiAccessTokenAuth: []
      responses:
        '200':
          description: Resource scopes updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      resource_scopes:
                        type: array
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                  message:
                    type: string
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                account_id_required:
                  summary: Account ID is required
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Account ID is required (provide account-id header or account_id in URL)
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_resource_scopes
                      method: PUT
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    success: false
                    error:
                      code: INVALID_TOKEN
                      message: Invalid token
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_resource_scopes
                      method: PUT
        '404':
          description: Not Found (custom role not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                custom_role_not_found:
                  summary: Custom role not found
                  value:
                    success: false
                    error:
                      code: NOT_FOUND
                      message: Custom role not found
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_resource_scopes
                      method: PUT
        '422':
          description: Unprocessable Entity (validation error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                validation_error:
                  summary: Validation failed
                  value:
                    success: false
                    error:
                      code: VALIDATION_ERROR
                      message: Validation failed
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                      path: /api/v1/custom_roles/{id}/update_resource_scopes
                      method: PUT
        '500':
          description: Internal Server Error (erro interno do servidor)
          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/custom_roles/{id}/update_resource_scopes
                      method: PUT
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                resource_scopes:
                  type: array
                  items:
                    type: object
                    properties:
                      resource_type:
                        type: string
                      resource_id:
                        type: string
                        format: uuid
                      actions:
                        type: array
                        items:
                          type: string
              required:
              - resource_scopes
components:
  schemas:
    CustomRole:
      type: object
      properties:
        id:
          type: string
          format: uuid
        key:
          type: string
        name:
          type: string
        description:
          type: string
          nullable: true
        is_active:
          type: boolean
        account_id:
          type: string
          format: uuid
        created_by_id:
          type: string
          format: uuid
          nullable: true
        updated_by_id:
          type: string
          format: uuid
          nullable: 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
  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
