Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

76.3 KB
Raw Blame
/**
 * Generated by orval v7.21.0 🍺
 * Do not edit manually.
 * properties_service
 * OpenAPI spec version: 0.1.0
 */
import * as zod from 'zod';

/**
 * @summary List property definitions with flexible filtering
 */
export const listPropertiesQueryParams = zod.object({
  scope: zod
    .enum(['user', 'team', 'system', 'all'])
    .describe("Filter by scope: 'user', 'team', 'system', or 'all'"),
  include_options: zod
    .boolean()
    .optional()
    .describe('Whether to include property options in the response'),
  for_entity_type: zod
    .enum([
      'CALENDAR_EVENT',
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'CONTACT',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'TASK',
      'THREAD',
      'USER',
    ])
    .optional()
    .describe('Filter properties applicable to a specific entity type'),
});

export const listPropertiesResponseItem = zod
  .union([
    zod
      .object({
        created_at: zod.iso.datetime({}),
        data_type: zod
          .enum([
            'BOOLEAN',
            'DATE',
            'DATE_RANGE',
            'NUMBER',
            'STRING',
            'SELECT_NUMBER',
            'SELECT_STRING',
            'TAG',
            'ENTITY',
            'LINK',
          ])
          .describe(
            'Data type for property values, determining storage and validation.'
          ),
        display_name: zod.string(),
        id: zod.uuid(),
        is_metadata: zod
          .boolean()
          .describe(
            'Flag to indicate if this is a system-generated metadata property.\nNot stored in database - computed at service layer.'
          ),
        is_multi_select: zod.boolean(),
        is_system: zod
          .boolean()
          .describe(
            'Flag to indicate if this is a system property (stored in DB).'
          ),
        owner: zod
          .union([
            zod
              .object({
                scope: zod.enum(['user']),
                user_id: zod.string(),
              })
              .describe('User-scoped property.'),
            zod
              .object({
                scope: zod.enum(['team']),
                team_id: zod.uuid(),
              })
              .describe('Team-scoped property.'),
            zod
              .object({
                database_id: zod.uuid(),
                scope: zod.enum(['database']),
              })
              .describe(
                'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
              ),
            zod
              .object({
                scope: zod.enum(['system']),
              })
              .describe(
                'System-owned property (no user, team, or database owner).'
              ),
          ])
          .describe(
            'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
          ),
        specific_entity_type: zod.union([
          zod.null(),
          zod
            .enum([
              'CALENDAR_EVENT',
              'CALL_RECORD',
              'CHANNEL',
              'CHAT',
              'COMPANY',
              'DATABASE_ROW',
              'CONTACT',
              'DOCUMENT',
              'INITIATIVE',
              'PROJECT',
              'TASK',
              'THREAD',
              'USER',
            ])
            .describe(
              'Type of entity that can be referenced by entity properties.'
            ),
        ]),
        updated_at: zod.iso.datetime({}),
      })
      .describe('Property definition model (service representation).'),
    zod
      .object({
        definition: zod
          .object({
            created_at: zod.iso.datetime({}),
            data_type: zod
              .enum([
                'BOOLEAN',
                'DATE',
                'DATE_RANGE',
                'NUMBER',
                'STRING',
                'SELECT_NUMBER',
                'SELECT_STRING',
                'TAG',
                'ENTITY',
                'LINK',
              ])
              .describe(
                'Data type for property values, determining storage and validation.'
              ),
            display_name: zod.string(),
            id: zod.uuid(),
            is_metadata: zod
              .boolean()
              .describe(
                'Flag to indicate if this is a system-generated metadata property.\nNot stored in database - computed at service layer.'
              ),
            is_multi_select: zod.boolean(),
            is_system: zod
              .boolean()
              .describe(
                'Flag to indicate if this is a system property (stored in DB).'
              ),
            owner: zod
              .union([
                zod
                  .object({
                    scope: zod.enum(['user']),
                    user_id: zod.string(),
                  })
                  .describe('User-scoped property.'),
                zod
                  .object({
                    scope: zod.enum(['team']),
                    team_id: zod.uuid(),
                  })
                  .describe('Team-scoped property.'),
                zod
                  .object({
                    database_id: zod.uuid(),
                    scope: zod.enum(['database']),
                  })
                  .describe(
                    'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
                  ),
                zod
                  .object({
                    scope: zod.enum(['system']),
                  })
                  .describe(
                    'System-owned property (no user, team, or database owner).'
                  ),
              ])
              .describe(
                'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
              ),
            specific_entity_type: zod.union([
              zod.null(),
              zod
                .enum([
                  'CALENDAR_EVENT',
                  'CALL_RECORD',
                  'CHANNEL',
                  'CHAT',
                  'COMPANY',
                  'DATABASE_ROW',
                  'CONTACT',
                  'DOCUMENT',
                  'INITIATIVE',
                  'PROJECT',
                  'TASK',
                  'THREAD',
                  'USER',
                ])
                .describe(
                  'Type of entity that can be referenced by entity properties.'
                ),
            ]),
            updated_at: zod.iso.datetime({}),
          })
          .describe('Property definition model (service representation).'),
        property_options: zod.array(
          zod
            .object({
              color: zod.string().nullable(),
              created_at: zod.iso.datetime({}),
              display_order: zod.number(),
              id: zod.uuid(),
              property_definition_id: zod.uuid(),
              updated_at: zod.iso.datetime({}),
              value: zod
                .union([
                  zod
                    .object({
                      type: zod.enum(['string']),
                      value: zod
                        .string()
                        .describe('String value for SelectString properties'),
                    })
                    .describe('String value for SelectString properties'),
                  zod
                    .object({
                      type: zod.enum(['number']),
                      value: zod
                        .number()
                        .describe('Number value for SelectNumber properties'),
                    })
                    .describe('Number value for SelectNumber properties'),
                ])
                .describe(
                  'The value of a property option - either a string or a number.'
                ),
            })
            .describe(
              'A selectable option for select-type properties (service representation).'
            )
        ),
      })
      .describe(
        'Property definition with its associated options (service representation).'
      ),
  ])
  .describe('Response for property definition with optional property options');
export const listPropertiesResponse = zod.array(listPropertiesResponseItem);

/**
 * @summary Create a new property definition
 */
export const createPropertyDefinitionBody = zod
  .object({
    data_type: zod
      .union([
        zod
          .object({
            type: zod.enum(['boolean']),
          })
          .describe('Boolean true\/false values.'),
        zod
          .object({
            type: zod.enum(['date']),
          })
          .describe('Date and time values.'),
        zod
          .object({
            type: zod.enum(['date_range']),
          })
          .describe('A span from a start date-time to an end one.'),
        zod
          .object({
            type: zod.enum(['number']),
          })
          .describe('Numeric values.'),
        zod
          .object({
            type: zod.enum(['string']),
          })
          .describe('String\/text values.'),
        zod
          .object({
            multi: zod.boolean(),
            options: zod.array(
              zod
                .object({
                  display_order: zod.number(),
                  value: zod.number(),
                })
                .describe('Option for select number properties in requests.')
            ),
            type: zod.enum(['select_number']),
          })
          .describe('Select property with numeric options.'),
        zod
          .object({
            multi: zod.boolean(),
            options: zod.array(
              zod
                .object({
                  display_order: zod.number(),
                  value: zod.string(),
                })
                .describe('Option for select-type properties in requests.')
            ),
            type: zod.enum(['select_string']),
          })
          .describe('Select property with string options.'),
        zod
          .object({
            multi: zod.boolean(),
            specific_type: zod
              .union([
                zod.null(),
                zod
                  .enum([
                    'CALENDAR_EVENT',
                    'CALL_RECORD',
                    'CHANNEL',
                    'CHAT',
                    'COMPANY',
                    'DATABASE_ROW',
                    'CONTACT',
                    'DOCUMENT',
                    'INITIATIVE',
                    'PROJECT',
                    'TASK',
                    'THREAD',
                    'USER',
                  ])
                  .describe(
                    'Type of entity that can be referenced by entity properties.'
                  ),
              ])
              .optional(),
            type: zod.enum(['entity']),
          })
          .describe('Entity reference property.'),
        zod
          .object({
            multi: zod.boolean(),
            type: zod.enum(['link']),
          })
          .describe('Link property.'),
      ])
      .describe(
        'Data type with embedded options for requests - provides compile-time validation.'
      ),
    display_name: zod.string(),
    scope: zod
      .enum(['user', 'team'])
      .describe(
        'Ownership scope a client may request when creating a property definition.\nThe owning user or team is derived server-side from the authenticated caller -\nclients never supply owner ids. System properties are not creatable via the API.'
      ),
  })
  .describe('Request to create a new property definition.');

/**
 * @summary Get a property definition by ID
 */
export const getPropertyDefinitionParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
});

export const getPropertyDefinitionResponse = zod
  .object({
    created_at: zod.iso.datetime({}),
    data_type: zod
      .enum([
        'BOOLEAN',
        'DATE',
        'DATE_RANGE',
        'NUMBER',
        'STRING',
        'SELECT_NUMBER',
        'SELECT_STRING',
        'TAG',
        'ENTITY',
        'LINK',
      ])
      .describe(
        'Data type for property values, determining storage and validation.'
      ),
    display_name: zod.string(),
    id: zod.uuid(),
    is_metadata: zod
      .boolean()
      .describe(
        'Flag to indicate if this is a system-generated metadata property.\nNot stored in database - computed at service layer.'
      ),
    is_multi_select: zod.boolean(),
    is_system: zod
      .boolean()
      .describe(
        'Flag to indicate if this is a system property (stored in DB).'
      ),
    owner: zod
      .union([
        zod
          .object({
            scope: zod.enum(['user']),
            user_id: zod.string(),
          })
          .describe('User-scoped property.'),
        zod
          .object({
            scope: zod.enum(['team']),
            team_id: zod.uuid(),
          })
          .describe('Team-scoped property.'),
        zod
          .object({
            database_id: zod.uuid(),
            scope: zod.enum(['database']),
          })
          .describe(
            'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
          ),
        zod
          .object({
            scope: zod.enum(['system']),
          })
          .describe(
            'System-owned property (no user, team, or database owner).'
          ),
      ])
      .describe(
        'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
      ),
    specific_entity_type: zod.union([
      zod.null(),
      zod
        .enum([
          'CALENDAR_EVENT',
          'CALL_RECORD',
          'CHANNEL',
          'CHAT',
          'COMPANY',
          'DATABASE_ROW',
          'CONTACT',
          'DOCUMENT',
          'INITIATIVE',
          'PROJECT',
          'TASK',
          'THREAD',
          'USER',
        ])
        .describe(
          'Type of entity that can be referenced by entity properties.'
        ),
    ]),
    updated_at: zod.iso.datetime({}),
  })
  .describe('Property definition model (service representation).');

/**
 * @summary Delete a property definition
 */
export const deletePropertyDefinitionParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
});

/**
 * @summary Get all options for a property (for dropdowns)
 */
export const getPropertyOptionsParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
});

export const getPropertyOptionsResponseItem = zod
  .object({
    color: zod.string().nullable(),
    created_at: zod.iso.datetime({}),
    display_order: zod.number(),
    id: zod.uuid(),
    property_definition_id: zod.uuid(),
    updated_at: zod.iso.datetime({}),
    value: zod
      .union([
        zod
          .object({
            type: zod.enum(['string']),
            value: zod
              .string()
              .describe('String value for SelectString properties'),
          })
          .describe('String value for SelectString properties'),
        zod
          .object({
            type: zod.enum(['number']),
            value: zod
              .number()
              .describe('Number value for SelectNumber properties'),
          })
          .describe('Number value for SelectNumber properties'),
      ])
      .describe(
        'The value of a property option - either a string or a number.'
      ),
  })
  .describe(
    'A selectable option for select-type properties (service representation).'
  );
export const getPropertyOptionsResponse = zod.array(
  getPropertyOptionsResponseItem
);

/**
 * @summary Add a new option to a property dropdown
 */
export const addPropertyOptionParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
});

export const addPropertyOptionBody = zod
  .union([
    zod
      .object({
        option: zod
          .object({
            color: zod.string().nullish(),
            display_order: zod.number(),
            value: zod.string(),
          })
          .describe(
            'Type-safe request to add a string option to a SelectString property.'
          ),
        type: zod.enum(['select_string']),
      })
      .describe('Add a string option to a SelectString property'),
    zod
      .object({
        option: zod
          .object({
            display_order: zod.number(),
            value: zod.number(),
          })
          .describe(
            'Type-safe request to add a number option to a SelectNumber property.'
          ),
        type: zod.enum(['select_number']),
      })
      .describe('Add a number option to a SelectNumber property'),
  ])
  .describe('Enum for type-safe property option addition requests.');

/**
 * @summary Delete a property option
 */
export const deletePropertyOptionParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
  option_id: zod.uuid().describe('Property option ID'),
});

/**
 * The option id is preserved, so the change is reflected on every entity that references it.
 * @summary Update a property option in place (rename / recolor / reorder).
 */
export const updatePropertyOptionParams = zod.object({
  definition_id: zod.uuid().describe('Property definition ID'),
  option_id: zod.uuid().describe('Property option ID'),
});

export const updatePropertyOptionBody = zod
  .object({
    color: zod
      .string()
      .nullish()
      .describe('New color as a hex string like `#RRGGBB`.'),
    display_order: zod.number().nullish().describe('New display order.'),
    value: zod
      .string()
      .nullish()
      .describe(
        'New string value (label text). Only valid for SelectString and Tag properties.'
      ),
  })
  .describe(
    'Request to update a property option in place. Omitted fields keep their current value.\nThe option id is preserved, so the change propagates to every entity referencing it.'
  );

export const updatePropertyOptionResponse = zod
  .object({
    color: zod.string().nullable(),
    created_at: zod.iso.datetime({}),
    display_order: zod.number(),
    id: zod.uuid(),
    property_definition_id: zod.uuid(),
    updated_at: zod.iso.datetime({}),
    value: zod
      .union([
        zod
          .object({
            type: zod.enum(['string']),
            value: zod
              .string()
              .describe('String value for SelectString properties'),
          })
          .describe('String value for SelectString properties'),
        zod
          .object({
            type: zod.enum(['number']),
            value: zod
              .number()
              .describe('Number value for SelectNumber properties'),
          })
          .describe('Number value for SelectNumber properties'),
      ])
      .describe(
        'The value of a property option - either a string or a number.'
      ),
  })
  .describe(
    'A selectable option for select-type properties (service representation).'
  );

/**
 * Only returns properties for entities the user has view permission for.
Entities without permission are silently omitted from the response.
 * @summary Get properties for multiple entities in bulk (public endpoint with user auth)
 */
export const getBulkEntityPropertiesBody = zod
  .object({
    entities: zod
      .array(
        zod
          .object({
            entity_id: zod.string().describe('Entity identifier.'),
            entity_type: zod
              .enum([
                'CALL_RECORD',
                'CHANNEL',
                'CHAT',
                'COMPANY',
                'DATABASE_ROW',
                'DOCUMENT',
                'INITIATIVE',
                'PROJECT',
                'THREAD',
                'USER',
              ])
              .describe(
                'Canonical type of an entity receiving properties.\n\nTasks are documents at API boundaries. `Task` intentionally does not exist\nhere; task classification is resolved by the properties domain from the\ndocument subtype.'
              ),
          })
          .describe('Canonical reference to an entity receiving properties.')
      )
      .describe('Array of entity references (entity_id and entity_type pairs)'),
    property_ids: zod
      .array(zod.uuid())
      .optional()
      .describe(
        'Optional: only return properties with these definition IDs. If empty, returns all.'
      ),
  })
  .describe('Request for getting properties for multiple entities in bulk');

export const getBulkEntityPropertiesResponse = zod.record(
  zod.string(),
  zod
    .object({
      entity_id: zod.string(),
      properties: zod.array(
        zod
          .object({
            definition: zod
              .object({
                created_at: zod.iso.datetime({}),
                data_type: zod
                  .enum([
                    'BOOLEAN',
                    'DATE',
                    'DATE_RANGE',
                    'NUMBER',
                    'STRING',
                    'SELECT_NUMBER',
                    'SELECT_STRING',
                    'TAG',
                    'ENTITY',
                    'LINK',
                  ])
                  .describe(
                    'Data type for property values, determining storage and validation.'
                  ),
                display_name: zod.string(),
                id: zod.uuid(),
                is_metadata: zod
                  .boolean()
                  .describe(
                    'Flag to indicate if this is a system-generated metadata property.\nNot stored in database - computed at service layer.'
                  ),
                is_multi_select: zod.boolean(),
                is_system: zod
                  .boolean()
                  .describe(
                    'Flag to indicate if this is a system property (stored in DB).'
                  ),
                owner: zod
                  .union([
                    zod
                      .object({
                        scope: zod.enum(['user']),
                        user_id: zod.string(),
                      })
                      .describe('User-scoped property.'),
                    zod
                      .object({
                        scope: zod.enum(['team']),
                        team_id: zod.uuid(),
                      })
                      .describe('Team-scoped property.'),
                    zod
                      .object({
                        database_id: zod.uuid(),
                        scope: zod.enum(['database']),
                      })
                      .describe(
                        'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
                      ),
                    zod
                      .object({
                        scope: zod.enum(['system']),
                      })
                      .describe(
                        'System-owned property (no user, team, or database owner).'
                      ),
                  ])
                  .describe(
                    'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
                  ),
                specific_entity_type: zod.union([
                  zod.null(),
                  zod
                    .enum([
                      'CALENDAR_EVENT',
                      'CALL_RECORD',
                      'CHANNEL',
                      'CHAT',
                      'COMPANY',
                      'DATABASE_ROW',
                      'CONTACT',
                      'DOCUMENT',
                      'INITIATIVE',
                      'PROJECT',
                      'TASK',
                      'THREAD',
                      'USER',
                    ])
                    .describe(
                      'Type of entity that can be referenced by entity properties.'
                    ),
                ]),
                updated_at: zod.iso.datetime({}),
              })
              .describe('Property definition model (service representation).'),
            options: zod
              .array(
                zod
                  .object({
                    color: zod.string().nullable(),
                    created_at: zod.iso.datetime({}),
                    display_order: zod.number(),
                    id: zod.uuid(),
                    property_definition_id: zod.uuid(),
                    updated_at: zod.iso.datetime({}),
                    value: zod
                      .union([
                        zod
                          .object({
                            type: zod.enum(['string']),
                            value: zod
                              .string()
                              .describe(
                                'String value for SelectString properties'
                              ),
                          })
                          .describe('String value for SelectString properties'),
                        zod
                          .object({
                            type: zod.enum(['number']),
                            value: zod
                              .number()
                              .describe(
                                'Number value for SelectNumber properties'
                              ),
                          })
                          .describe('Number value for SelectNumber properties'),
                      ])
                      .describe(
                        'The value of a property option - either a string or a number.'
                      ),
                  })
                  .describe(
                    'A selectable option for select-type properties (service representation).'
                  )
              )
              .nullish(),
            property: zod
              .object({
                created_at: zod.iso.datetime({}),
                entity_id: zod.string(),
                entity_type: zod
                  .enum([
                    'CALENDAR_EVENT',
                    'CALL_RECORD',
                    'CHANNEL',
                    'CHAT',
                    'COMPANY',
                    'DATABASE_ROW',
                    'CONTACT',
                    'DOCUMENT',
                    'INITIATIVE',
                    'PROJECT',
                    'TASK',
                    'THREAD',
                    'USER',
                  ])
                  .describe(
                    'Type of entity that can be referenced by entity properties.'
                  ),
                id: zod.uuid(),
                property_definition_id: zod.uuid(),
                updated_at: zod.iso.datetime({}),
              })
              .describe(
                'Assignment of a property definition to a specific entity (service representation).'
              ),
            value: zod
              .union([
                zod.null(),
                zod
                  .union([
                    zod
                      .object({
                        type: zod.enum(['Boolean']),
                        value: zod
                          .boolean()
                          .describe(
                            'Boolean value\nSerializes as: {\"type\": \"Boolean\", \"value\": true}'
                          ),
                      })
                      .describe(
                        'Boolean value\nSerializes as: {\"type\": \"Boolean\", \"value\": true}'
                      ),
                    zod
                      .object({
                        type: zod.enum(['Number']),
                        value: zod
                          .number()
                          .describe(
                            'Numeric value\nSerializes as: {\"type\": \"Number\", \"value\": 42.5}'
                          ),
                      })
                      .describe(
                        'Numeric value\nSerializes as: {\"type\": \"Number\", \"value\": 42.5}'
                      ),
                    zod
                      .object({
                        type: zod.enum(['String']),
                        value: zod
                          .string()
                          .describe(
                            'String value\nSerializes as: {\"type\": \"String\", \"value\": \"text\"}'
                          ),
                      })
                      .describe(
                        'String value\nSerializes as: {\"type\": \"String\", \"value\": \"text\"}'
                      ),
                    zod
                      .object({
                        type: zod.enum(['Date']),
                        value: zod.iso
                          .datetime({})
                          .describe(
                            'Date\/timestamp value\nSerializes as: {\"type\": \"Date\", \"value\": \"2025-01-01T00:00:00Z\"}'
                          ),
                      })
                      .describe(
                        'Date\/timestamp value\nSerializes as: {\"type\": \"Date\", \"value\": \"2025-01-01T00:00:00Z\"}'
                      ),
                    zod
                      .object({
                        type: zod.enum(['DateRange']),
                        value: zod
                          .object({
                            end: zod.iso.datetime({}),
                            start: zod.iso.datetime({}),
                          })
                          .describe(
                            'A span of time from `start` to `end`, both included. The end is never\nbefore the start: a range that would end earlier does not deserialize.'
                          ),
                      })
                      .describe(
                        'Date range value\nSerializes as: {\"type\": \"DateRange\", \"value\": {\"start\": \"2025-01-01T00:00:00Z\", \"end\": \"2025-01-31T00:00:00Z\"}}'
                      ),
                    zod
                      .object({
                        type: zod.enum(['SelectOption']),
                        value: zod
                          .array(zod.uuid())
                          .describe(
                            'Select option(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"SelectOption\", \"value\": [\"uuid\"]} (length 0 or 1)\nMulti-select: {\"type\": \"SelectOption\", \"value\": [\"uuid1\", \"uuid2\", ...]} (length 0+)'
                          ),
                      })
                      .describe(
                        'Select option(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"SelectOption\", \"value\": [\"uuid\"]} (length 0 or 1)\nMulti-select: {\"type\": \"SelectOption\", \"value\": [\"uuid1\", \"uuid2\", ...]} (length 0+)'
                      ),
                    zod
                      .object({
                        type: zod.enum(['EntityReference']),
                        value: zod
                          .array(
                            zod
                              .object({
                                entity_id: zod.string(),
                                entity_type: zod
                                  .enum([
                                    'CALENDAR_EVENT',
                                    'CALL_RECORD',
                                    'CHANNEL',
                                    'CHAT',
                                    'COMPANY',
                                    'DATABASE_ROW',
                                    'CONTACT',
                                    'DOCUMENT',
                                    'INITIATIVE',
                                    'PROJECT',
                                    'TASK',
                                    'THREAD',
                                    'USER',
                                  ])
                                  .describe(
                                    'Type of entity that can be referenced by entity properties.'
                                  ),
                                specific_message_id: zod
                                  .uuid()
                                  .nullish()
                                  .describe(
                                    'For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread\/channel\/chat.'
                                  ),
                              })
                              .describe(
                                'Entity reference for entity-type property values.'
                              )
                          )
                          .describe(
                            'Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)'
                          ),
                      })
                      .describe(
                        'Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)'
                      ),
                    zod
                      .object({
                        type: zod.enum(['Link']),
                        value: zod
                          .array(zod.string())
                          .describe(
                            'Link value(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\"]} (length 0 or 1)\nMulti-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\", \"https:\/\/other.com\"]} (length 0+)'
                          ),
                      })
                      .describe(
                        'Link value(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\"]} (length 0 or 1)\nMulti-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\", \"https:\/\/other.com\"]} (length 0+)'
                      ),
                  ])
                  .describe(
                    'Property value (service representation).\n\nRepresents the actual value stored for an entity property.\nThis is serialized to\/from JSONB in the database.'
                  ),
              ])
              .optional(),
          })
          .describe(
            'Entity property with its definition, value, and options (service representation).'
          )
      ),
    })
    .describe('Response for document\/entity properties endpoint.')
);

/**
 * @summary Get all properties for an entity
 */
export const getEntityPropertiesParams = zod.object({
  entity_type: zod
    .enum([
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'THREAD',
      'USER',
    ])
    .describe('Canonical entity type; tasks use DOCUMENT'),
  entity_id: zod.string().describe('Entity ID'),
});

export const getEntityPropertiesQueryParams = zod.object({
  include_metadata: zod
    .boolean()
    .optional()
    .describe('Whether to include property metadata (default: false)'),
});

export const getEntityPropertiesResponse = zod
  .object({
    entity_id: zod.string(),
    properties: zod.array(
      zod
        .object({
          definition: zod
            .object({
              created_at: zod.iso.datetime({}),
              data_type: zod
                .enum([
                  'BOOLEAN',
                  'DATE',
                  'DATE_RANGE',
                  'NUMBER',
                  'STRING',
                  'SELECT_NUMBER',
                  'SELECT_STRING',
                  'TAG',
                  'ENTITY',
                  'LINK',
                ])
                .describe(
                  'Data type for property values, determining storage and validation.'
                ),
              display_name: zod.string(),
              id: zod.uuid(),
              is_metadata: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system-generated metadata property.\nNot stored in database - computed at service layer.'
                ),
              is_multi_select: zod.boolean(),
              is_system: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system property (stored in DB).'
                ),
              owner: zod
                .union([
                  zod
                    .object({
                      scope: zod.enum(['user']),
                      user_id: zod.string(),
                    })
                    .describe('User-scoped property.'),
                  zod
                    .object({
                      scope: zod.enum(['team']),
                      team_id: zod.uuid(),
                    })
                    .describe('Team-scoped property.'),
                  zod
                    .object({
                      database_id: zod.uuid(),
                      scope: zod.enum(['database']),
                    })
                    .describe(
                      'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
                    ),
                  zod
                    .object({
                      scope: zod.enum(['system']),
                    })
                    .describe(
                      'System-owned property (no user, team, or database owner).'
                    ),
                ])
                .describe(
                  'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
                ),
              specific_entity_type: zod.union([
                zod.null(),
                zod
                  .enum([
                    'CALENDAR_EVENT',
                    'CALL_RECORD',
                    'CHANNEL',
                    'CHAT',
                    'COMPANY',
                    'DATABASE_ROW',
                    'CONTACT',
                    'DOCUMENT',
                    'INITIATIVE',
                    'PROJECT',
                    'TASK',
                    'THREAD',
                    'USER',
                  ])
                  .describe(
                    'Type of entity that can be referenced by entity properties.'
                  ),
              ]),
              updated_at: zod.iso.datetime({}),
            })
            .describe('Property definition model (service representation).'),
          options: zod
            .array(
              zod
                .object({
                  color: zod.string().nullable(),
                  created_at: zod.iso.datetime({}),
                  display_order: zod.number(),
                  id: zod.uuid(),
                  property_definition_id: zod.uuid(),
                  updated_at: zod.iso.datetime({}),
                  value: zod
                    .union([
                      zod
                        .object({
                          type: zod.enum(['string']),
                          value: zod
                            .string()
                            .describe(
                              'String value for SelectString properties'
                            ),
                        })
                        .describe('String value for SelectString properties'),
                      zod
                        .object({
                          type: zod.enum(['number']),
                          value: zod
                            .number()
                            .describe(
                              'Number value for SelectNumber properties'
                            ),
                        })
                        .describe('Number value for SelectNumber properties'),
                    ])
                    .describe(
                      'The value of a property option - either a string or a number.'
                    ),
                })
                .describe(
                  'A selectable option for select-type properties (service representation).'
                )
            )
            .nullish(),
          property: zod
            .object({
              created_at: zod.iso.datetime({}),
              entity_id: zod.string(),
              entity_type: zod
                .enum([
                  'CALENDAR_EVENT',
                  'CALL_RECORD',
                  'CHANNEL',
                  'CHAT',
                  'COMPANY',
                  'DATABASE_ROW',
                  'CONTACT',
                  'DOCUMENT',
                  'INITIATIVE',
                  'PROJECT',
                  'TASK',
                  'THREAD',
                  'USER',
                ])
                .describe(
                  'Type of entity that can be referenced by entity properties.'
                ),
              id: zod.uuid(),
              property_definition_id: zod.uuid(),
              updated_at: zod.iso.datetime({}),
            })
            .describe(
              'Assignment of a property definition to a specific entity (service representation).'
            ),
          value: zod
            .union([
              zod.null(),
              zod
                .union([
                  zod
                    .object({
                      type: zod.enum(['Boolean']),
                      value: zod
                        .boolean()
                        .describe(
                          'Boolean value\nSerializes as: {\"type\": \"Boolean\", \"value\": true}'
                        ),
                    })
                    .describe(
                      'Boolean value\nSerializes as: {\"type\": \"Boolean\", \"value\": true}'
                    ),
                  zod
                    .object({
                      type: zod.enum(['Number']),
                      value: zod
                        .number()
                        .describe(
                          'Numeric value\nSerializes as: {\"type\": \"Number\", \"value\": 42.5}'
                        ),
                    })
                    .describe(
                      'Numeric value\nSerializes as: {\"type\": \"Number\", \"value\": 42.5}'
                    ),
                  zod
                    .object({
                      type: zod.enum(['String']),
                      value: zod
                        .string()
                        .describe(
                          'String value\nSerializes as: {\"type\": \"String\", \"value\": \"text\"}'
                        ),
                    })
                    .describe(
                      'String value\nSerializes as: {\"type\": \"String\", \"value\": \"text\"}'
                    ),
                  zod
                    .object({
                      type: zod.enum(['Date']),
                      value: zod.iso
                        .datetime({})
                        .describe(
                          'Date\/timestamp value\nSerializes as: {\"type\": \"Date\", \"value\": \"2025-01-01T00:00:00Z\"}'
                        ),
                    })
                    .describe(
                      'Date\/timestamp value\nSerializes as: {\"type\": \"Date\", \"value\": \"2025-01-01T00:00:00Z\"}'
                    ),
                  zod
                    .object({
                      type: zod.enum(['DateRange']),
                      value: zod
                        .object({
                          end: zod.iso.datetime({}),
                          start: zod.iso.datetime({}),
                        })
                        .describe(
                          'A span of time from `start` to `end`, both included. The end is never\nbefore the start: a range that would end earlier does not deserialize.'
                        ),
                    })
                    .describe(
                      'Date range value\nSerializes as: {\"type\": \"DateRange\", \"value\": {\"start\": \"2025-01-01T00:00:00Z\", \"end\": \"2025-01-31T00:00:00Z\"}}'
                    ),
                  zod
                    .object({
                      type: zod.enum(['SelectOption']),
                      value: zod
                        .array(zod.uuid())
                        .describe(
                          'Select option(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"SelectOption\", \"value\": [\"uuid\"]} (length 0 or 1)\nMulti-select: {\"type\": \"SelectOption\", \"value\": [\"uuid1\", \"uuid2\", ...]} (length 0+)'
                        ),
                    })
                    .describe(
                      'Select option(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"SelectOption\", \"value\": [\"uuid\"]} (length 0 or 1)\nMulti-select: {\"type\": \"SelectOption\", \"value\": [\"uuid1\", \"uuid2\", ...]} (length 0+)'
                    ),
                  zod
                    .object({
                      type: zod.enum(['EntityReference']),
                      value: zod
                        .array(
                          zod
                            .object({
                              entity_id: zod.string(),
                              entity_type: zod
                                .enum([
                                  'CALENDAR_EVENT',
                                  'CALL_RECORD',
                                  'CHANNEL',
                                  'CHAT',
                                  'COMPANY',
                                  'DATABASE_ROW',
                                  'CONTACT',
                                  'DOCUMENT',
                                  'INITIATIVE',
                                  'PROJECT',
                                  'TASK',
                                  'THREAD',
                                  'USER',
                                ])
                                .describe(
                                  'Type of entity that can be referenced by entity properties.'
                                ),
                              specific_message_id: zod
                                .uuid()
                                .nullish()
                                .describe(
                                  'For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread\/channel\/chat.'
                                ),
                            })
                            .describe(
                              'Entity reference for entity-type property values.'
                            )
                        )
                        .describe(
                          'Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)'
                        ),
                    })
                    .describe(
                      'Entity reference(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"EntityReference\", \"value\": [{...}]} (length 0 or 1)\nMulti-select: {\"type\": \"EntityReference\", \"value\": [{...}, {...}, ...]} (length 0+)'
                    ),
                  zod
                    .object({
                      type: zod.enum(['Link']),
                      value: zod
                        .array(zod.string())
                        .describe(
                          'Link value(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\"]} (length 0 or 1)\nMulti-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\", \"https:\/\/other.com\"]} (length 0+)'
                        ),
                    })
                    .describe(
                      'Link value(s) - always an array (check is_multi_select to determine if single or multi)\nSingle-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\"]} (length 0 or 1)\nMulti-select: {\"type\": \"Link\", \"value\": [\"https:\/\/example.com\", \"https:\/\/other.com\"]} (length 0+)'
                    ),
                ])
                .describe(
                  'Property value (service representation).\n\nRepresents the actual value stored for an entity property.\nThis is serialized to\/from JSONB in the database.'
                ),
            ])
            .optional(),
        })
        .describe(
          'Entity property with its definition, value, and options (service representation).'
        )
    ),
  })
  .describe('Response for document\/entity properties endpoint.');

/**
 * Each property change is expressed as an option delta and applied to the
current stored value under a per-row lock inside a single transaction, so the
selection persists atomically and composes with concurrent edits instead of
clobbering them. Returns the reconciled final option ids per property for
cache reconciliation.
 * @summary Apply a complete tag-picker selection across an entity's multi-select
properties in one request.
 */
export const bulkUpdateEntityPropertyOptionsParams = zod.object({
  entity_type: zod
    .enum([
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'THREAD',
      'USER',
    ])
    .describe('Canonical entity type; tasks use DOCUMENT'),
  entity_id: zod.string().describe('Entity ID'),
});

export const bulkUpdateEntityPropertyOptionsBody = zod
  .object({
    properties: zod
      .array(
        zod
          .object({
            add_option_ids: zod
              .array(zod.uuid())
              .optional()
              .describe('Options to add (deduped against the current value).'),
            property_id: zod
              .uuid()
              .describe('The multi-select property definition being changed.'),
            remove_option_ids: zod
              .array(zod.uuid())
              .optional()
              .describe('Options to remove (a no-op if not present).'),
          })
          .describe(
            "One property's option changes in a bulk selection update. The change is a\ndelta (options to add \/ remove) so it composes with concurrent edits rather\nthan replacing the whole value."
          )
      )
      .describe('The per-property option changes to apply.'),
  })
  .describe(
    "Request to apply option deltas across one or more of an entity's multi-select\nproperties in a single transaction."
  );

export const bulkUpdateEntityPropertyOptionsResponse = zod
  .object({
    properties: zod
      .array(
        zod
          .object({
            option_ids: zod
              .array(zod.uuid())
              .describe(
                'The final option ids the server persisted, in stored order.'
              ),
            property_id: zod
              .uuid()
              .describe('The property definition the options belong to.'),
          })
          .describe(
            'The reconciled final option ids stored for one property after a bulk update.'
          )
      )
      .describe('The final option ids per updated property.'),
  })
  .describe(
    "Response for a bulk option update: each property's reconciled final ids."
  );

/**
 * @summary Set or update a property value for an entity, or attach a property without a value
 */
export const setEntityPropertyParams = zod.object({
  entity_type: zod
    .enum([
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'THREAD',
      'USER',
    ])
    .describe('Canonical entity type; tasks use DOCUMENT'),
  entity_id: zod.string().describe('Entity ID'),
  property_id: zod.uuid().describe('Property ID'),
});

export const setEntityPropertyBody = zod
  .object({
    value: zod
      .union([
        zod.null(),
        zod
          .union([
            zod
              .object({
                type: zod.enum(['boolean']),
                value: zod.boolean(),
              })
              .describe('Boolean true\/false value'),
            zod
              .object({
                type: zod.enum(['date']),
                value: zod.iso.datetime({}),
              })
              .describe('Date and time value'),
            zod
              .object({
                type: zod.enum(['date_range']),
                value: zod
                  .object({
                    end: zod.iso.datetime({}),
                    start: zod.iso.datetime({}),
                  })
                  .describe(
                    'A span of time from `start` to `end`, both included. The end is never\nbefore the start: a range that would end earlier does not deserialize.'
                  ),
              })
              .describe('Date range value'),
            zod
              .object({
                type: zod.enum(['number']),
                value: zod.number(),
              })
              .describe('Numeric value'),
            zod
              .object({
                type: zod.enum(['string']),
                value: zod.string(),
              })
              .describe('String\/text value'),
            zod
              .object({
                option_id: zod.uuid(),
                type: zod.enum(['select_option']),
              })
              .describe('Select option by ID (for select-type properties)'),
            zod
              .object({
                option_ids: zod.array(zod.uuid()),
                type: zod.enum(['multi_select_option']),
              })
              .describe(
                'Multiple select options by ID (for multi-select properties)'
              ),
            zod
              .object({
                reference: zod
                  .object({
                    entity_id: zod.string(),
                    entity_type: zod
                      .enum([
                        'CALENDAR_EVENT',
                        'CALL_RECORD',
                        'CHANNEL',
                        'CHAT',
                        'COMPANY',
                        'DATABASE_ROW',
                        'CONTACT',
                        'DOCUMENT',
                        'INITIATIVE',
                        'PROJECT',
                        'TASK',
                        'THREAD',
                        'USER',
                      ])
                      .describe(
                        'Type of entity that can be referenced by entity properties.'
                      ),
                    specific_message_id: zod
                      .uuid()
                      .nullish()
                      .describe(
                        'For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread\/channel\/chat.'
                      ),
                  })
                  .describe(
                    'Entity reference for entity-type property values.'
                  ),
                type: zod.enum(['entity_reference']),
              })
              .describe('Entity reference'),
            zod
              .object({
                references: zod.array(
                  zod
                    .object({
                      entity_id: zod.string(),
                      entity_type: zod
                        .enum([
                          'CALENDAR_EVENT',
                          'CALL_RECORD',
                          'CHANNEL',
                          'CHAT',
                          'COMPANY',
                          'DATABASE_ROW',
                          'CONTACT',
                          'DOCUMENT',
                          'INITIATIVE',
                          'PROJECT',
                          'TASK',
                          'THREAD',
                          'USER',
                        ])
                        .describe(
                          'Type of entity that can be referenced by entity properties.'
                        ),
                      specific_message_id: zod
                        .uuid()
                        .nullish()
                        .describe(
                          'For CHANNEL, CHAT, THREAD entity types - optional specific message ID.\nThis allows referencing a specific message within a thread\/channel\/chat.'
                        ),
                    })
                    .describe(
                      'Entity reference for entity-type property values.'
                    )
                ),
                type: zod.enum(['multi_entity_reference']),
              })
              .describe(
                'Multiple entity references (for multi-select entity properties)'
              ),
            zod
              .object({
                type: zod.enum(['link']),
                url: zod.string(),
              })
              .describe('Link value'),
            zod
              .object({
                type: zod.enum(['multi_link']),
                urls: zod.array(zod.string()),
              })
              .describe(
                'Multiple link values (for multi-select link properties)'
              ),
          ])
          .describe(
            'Type-safe enum for setting entity property values - provides compile-time validation.'
          ),
      ])
      .optional(),
  })
  .describe('Type-safe request for setting entity property values.');

/**
 * Atomic delta: the option is appended to the current stored value (deduped,
attaching the property if needed), so concurrent edits to the same value
merge rather than overwrite each other. Prefer this over the full-value PUT
when adding one option.
 * @summary Add a single option to an entity's multi-select property value.
 */
export const addEntityPropertyOptionParams = zod.object({
  entity_type: zod
    .enum([
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'THREAD',
      'USER',
    ])
    .describe('Canonical entity type; tasks use DOCUMENT'),
  entity_id: zod.string().describe('Entity ID'),
  property_id: zod.uuid().describe('Property ID'),
  option_id: zod.uuid().describe('Option ID to add'),
});

/**
 * Atomic delta: the option is stripped from the current stored value (a no-op
if absent), so concurrent edits to the same value merge rather than overwrite
each other.
 * @summary Remove a single option from an entity's multi-select property value.
 */
export const removeEntityPropertyOptionParams = zod.object({
  entity_type: zod
    .enum([
      'CALL_RECORD',
      'CHANNEL',
      'CHAT',
      'COMPANY',
      'DATABASE_ROW',
      'DOCUMENT',
      'INITIATIVE',
      'PROJECT',
      'THREAD',
      'USER',
    ])
    .describe('Canonical entity type; tasks use DOCUMENT'),
  entity_id: zod.string().describe('Entity ID'),
  property_id: zod.uuid().describe('Property ID'),
  option_id: zod.uuid().describe('Option ID to remove'),
});

/**
 * @summary Remove a specific entity property by its ID
 */
export const deleteEntityPropertyParams = zod.object({
  entity_property_id: zod.uuid().describe('Entity Property ID'),
});

/**
 * Best-effort per entity: one edit receipt is minted per entity, entities the
caller can't edit are reported as `skipped_no_permission` (mirroring the
read path, which silently drops entities the caller can't view), and each
permitted entity is updated in its own transaction so one entity failing
does not roll back the others. Returns one result per requested entity in
request order, with the reconciled final option ids for the successes.
 * @summary Apply one shared option delta (add / remove option ids on a single
multi-select property) to many entities in one request — e.g. tag a set of
emails with one label.
 */
export const bulkUpdateEntitiesPropertyOptionsBody = zod
  .object({
    add_option_ids: zod
      .array(zod.uuid())
      .optional()
      .describe("Options to add to each entity's current value (deduped)."),
    entities: zod
      .array(
        zod
          .object({
            entity_id: zod.string().describe('Entity identifier.'),
            entity_type: zod
              .enum([
                'CALL_RECORD',
                'CHANNEL',
                'CHAT',
                'COMPANY',
                'DATABASE_ROW',
                'DOCUMENT',
                'INITIATIVE',
                'PROJECT',
                'THREAD',
                'USER',
              ])
              .describe(
                'Canonical type of an entity receiving properties.\n\nTasks are documents at API boundaries. `Task` intentionally does not exist\nhere; task classification is resolved by the properties domain from the\ndocument subtype.'
              ),
          })
          .describe('Canonical reference to an entity receiving properties.')
      )
      .describe(
        'The entities to update. Entities the caller cannot edit are skipped.'
      ),
    property_id: zod
      .uuid()
      .describe(
        'The multi-select property definition changed on every entity.'
      ),
    remove_option_ids: zod
      .array(zod.uuid())
      .optional()
      .describe(
        "Options to remove from each entity's current value (a no-op if absent)."
      ),
  })
  .describe(
    "Request to apply one shared option delta across several entities in a single\ncall. Mirrors the per-entity bulk endpoint's delta semantics, applied to\nevery listed entity (e.g. tag N emails with one label in one request)."
  );

export const bulkUpdateEntitiesPropertyOptionsResponse = zod
  .object({
    results: zod
      .array(
        zod
          .object({
            entity_id: zod
              .string()
              .describe("The entity's id this result is for."),
            entity_type: zod
              .enum([
                'CALL_RECORD',
                'CHANNEL',
                'CHAT',
                'COMPANY',
                'DATABASE_ROW',
                'DOCUMENT',
                'INITIATIVE',
                'PROJECT',
                'THREAD',
                'USER',
              ])
              .describe(
                'Canonical type of an entity receiving properties.\n\nTasks are documents at API boundaries. `Task` intentionally does not exist\nhere; task classification is resolved by the properties domain from the\ndocument subtype.'
              ),
            error: zod
              .string()
              .nullish()
              .describe('A human-readable reason, present only when `failed`.'),
            option_ids: zod
              .array(zod.uuid())
              .nullish()
              .describe(
                "The entity's reconciled final option ids, present only when `applied`."
              ),
            status: zod
              .enum(['applied', 'skipped_no_permission', 'failed'])
              .describe(
                'Per-entity outcome of a cross-entity bulk option update.'
              ),
          })
          .describe("One entity's result in a cross-entity bulk option update.")
      )
      .describe(
        "Per-entity results, aligned to the request's `entities` order."
      ),
  })
  .describe(
    'Response for a cross-entity bulk option update: one result per requested\nentity, in request order.'
  );

/**
 * @summary List the caller's tag sets: their personal set, plus their team's set when on a team.
Pure read - a scope with no provisioned definition yet returns an empty set.
 */
export const listTagsResponseItem = zod
  .object({
    definition: zod
      .union([
        zod.null(),
        zod
          .union([
            zod
              .object({
                scope: zod.enum(['user']),
                user_id: zod.string(),
              })
              .describe('User-scoped property.'),
            zod
              .object({
                scope: zod.enum(['team']),
                team_id: zod.uuid(),
              })
              .describe('Team-scoped property.'),
            zod
              .object({
                database_id: zod.uuid(),
                scope: zod.enum(['database']),
              })
              .describe(
                'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
              ),
            zod
              .object({
                scope: zod.enum(['system']),
              })
              .describe(
                'System-owned property (no user, team, or database owner).'
              ),
          ])
          .describe(
            'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
          )
          .and(
            zod.object({
              createdAt: zod.iso.datetime({}).nullish(),
              dataType: zod
                .enum([
                  'BOOLEAN',
                  'DATE',
                  'DATE_RANGE',
                  'NUMBER',
                  'STRING',
                  'SELECT_NUMBER',
                  'SELECT_STRING',
                  'TAG',
                  'ENTITY',
                  'LINK',
                ])
                .describe(
                  'Data type for property values, determining storage and validation.'
                ),
              displayName: zod.string(),
              id: zod.uuid(),
              isMetadata: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system-generated metadata property'
                ),
              isMultiSelect: zod.boolean(),
              isSystem: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system property (managed by the system)'
                ),
              specificEntityType: zod
                .union([
                  zod.null(),
                  zod
                    .enum([
                      'CALENDAR_EVENT',
                      'CALL_RECORD',
                      'CHANNEL',
                      'CHAT',
                      'COMPANY',
                      'DATABASE_ROW',
                      'CONTACT',
                      'DOCUMENT',
                      'INITIATIVE',
                      'PROJECT',
                      'TASK',
                      'THREAD',
                      'USER',
                    ])
                    .describe(
                      'Type of entity that can be referenced by entity properties.'
                    ),
                ])
                .optional(),
              updatedAt: zod.iso.datetime({}).nullish(),
            })
          )
          .describe('Property definition response (API representation).'),
      ])
      .optional(),
    options: zod.array(
      zod
        .object({
          color: zod.string().nullish(),
          displayOrder: zod.number(),
          id: zod.uuid(),
          propertyDefinitionId: zod.uuid(),
          value: zod
            .union([
              zod
                .object({
                  type: zod.enum(['string']),
                  value: zod
                    .string()
                    .describe('String value for SelectString properties'),
                })
                .describe('String value for SelectString properties'),
              zod
                .object({
                  type: zod.enum(['number']),
                  value: zod
                    .number()
                    .describe('Number value for SelectNumber properties'),
                })
                .describe('Number value for SelectNumber properties'),
            ])
            .describe(
              'The value of a property option - either a string or a number.'
            ),
        })
        .describe('Property option response (API representation).')
    ),
    scope: zod
      .enum(['user', 'team'])
      .describe('Which owner a tag set belongs to.'),
  })
  .describe(
    'A tag set the caller can use. `definition` is absent until the set is provisioned\n(on first label create), in which case `options` is empty.'
  );
export const listTagsResponse = zod.array(listTagsResponseItem);

/**
 * @summary Provision (get-or-create) the caller's tag set for a scope and return it. Called when
the caller creates their first label for that scope, so the read path stays side-effect free.
 */
export const ensureTagSetBody = zod
  .object({
    scope: zod
      .enum(['user', 'team'])
      .describe('Which owner a tag set belongs to.'),
  })
  .describe(
    "Request to provision (get-or-create) the caller's tag set for a scope."
  );

export const ensureTagSetResponse = zod
  .object({
    definition: zod
      .union([
        zod.null(),
        zod
          .union([
            zod
              .object({
                scope: zod.enum(['user']),
                user_id: zod.string(),
              })
              .describe('User-scoped property.'),
            zod
              .object({
                scope: zod.enum(['team']),
                team_id: zod.uuid(),
              })
              .describe('Team-scoped property.'),
            zod
              .object({
                database_id: zod.uuid(),
                scope: zod.enum(['database']),
              })
              .describe(
                'Database-scoped property: the definition is a column of one Macro\ndatabase and is invisible to the shared user\/team property namespace.'
              ),
            zod
              .object({
                scope: zod.enum(['system']),
              })
              .describe(
                'System-owned property (no user, team, or database owner).'
              ),
          ])
          .describe(
            'Defines who owns a property - user-scoped, team-scoped, database-scoped, or system.'
          )
          .and(
            zod.object({
              createdAt: zod.iso.datetime({}).nullish(),
              dataType: zod
                .enum([
                  'BOOLEAN',
                  'DATE',
                  'DATE_RANGE',
                  'NUMBER',
                  'STRING',
                  'SELECT_NUMBER',
                  'SELECT_STRING',
                  'TAG',
                  'ENTITY',
                  'LINK',
                ])
                .describe(
                  'Data type for property values, determining storage and validation.'
                ),
              displayName: zod.string(),
              id: zod.uuid(),
              isMetadata: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system-generated metadata property'
                ),
              isMultiSelect: zod.boolean(),
              isSystem: zod
                .boolean()
                .describe(
                  'Flag to indicate if this is a system property (managed by the system)'
                ),
              specificEntityType: zod
                .union([
                  zod.null(),
                  zod
                    .enum([
                      'CALENDAR_EVENT',
                      'CALL_RECORD',
                      'CHANNEL',
                      'CHAT',
                      'COMPANY',
                      'DATABASE_ROW',
                      'CONTACT',
                      'DOCUMENT',
                      'INITIATIVE',
                      'PROJECT',
                      'TASK',
                      'THREAD',
                      'USER',
                    ])
                    .describe(
                      'Type of entity that can be referenced by entity properties.'
                    ),
                ])
                .optional(),
              updatedAt: zod.iso.datetime({}).nullish(),
            })
          )
          .describe('Property definition response (API representation).'),
      ])
      .optional(),
    options: zod.array(
      zod
        .object({
          color: zod.string().nullish(),
          displayOrder: zod.number(),
          id: zod.uuid(),
          propertyDefinitionId: zod.uuid(),
          value: zod
            .union([
              zod
                .object({
                  type: zod.enum(['string']),
                  value: zod
                    .string()
                    .describe('String value for SelectString properties'),
                })
                .describe('String value for SelectString properties'),
              zod
                .object({
                  type: zod.enum(['number']),
                  value: zod
                    .number()
                    .describe('Number value for SelectNumber properties'),
                })
                .describe('Number value for SelectNumber properties'),
            ])
            .describe(
              'The value of a property option - either a string or a number.'
            ),
        })
        .describe('Property option response (API representation).')
    ),
    scope: zod
      .enum(['user', 'team'])
      .describe('Which owner a tag set belongs to.'),
  })
  .describe(
    'A tag set the caller can use. `definition` is absent until the set is provisioned\n(on first label create), in which case `options` is empty.'
  );

/**
 * Every entity carrying the personal label is retagged with the team label
(deduped if it already has both) and the personal label is deleted. The team
label's name and color win. This is the confirmation step after the promote
endpoint reports a name collision.
 * @summary Replace one of the caller's personal labels with an existing team label.
 */
export const mergeTagBody = zod
  .object({
    option_id: zod.uuid().describe('The personal label to retire.'),
    target_option_id: zod
      .uuid()
      .describe(
        'The team label every entity carrying `option_id` is retagged with.'
      ),
  })
  .describe('Request to replace a personal label with an existing team label.');

export const mergeTagResponse = zod
  .object({
    color: zod.string().nullish(),
    displayOrder: zod.number(),
    id: zod.uuid(),
    propertyDefinitionId: zod.uuid(),
    value: zod
      .union([
        zod
          .object({
            type: zod.enum(['string']),
            value: zod
              .string()
              .describe('String value for SelectString properties'),
          })
          .describe('String value for SelectString properties'),
        zod
          .object({
            type: zod.enum(['number']),
            value: zod
              .number()
              .describe('Number value for SelectNumber properties'),
          })
          .describe('Number value for SelectNumber properties'),
      ])
      .describe(
        'The value of a property option - either a string or a number.'
      ),
  })
  .describe('Property option response (API representation).');

/**
 * The label moves into the team tag set keeping its option id, so every entity
already carrying it keeps the label — it just becomes visible to, and usable
by, the whole team. A 409 means the team already has a label with that name;
its body carries that label, and confirming the replacement is a call to the
merge endpoint with `conflicting_option.id` as `target_option_id`.
 * @summary Share one of the caller's personal labels with their team.
 */
export const promoteTagBody = zod
  .object({
    option_id: zod
      .uuid()
      .describe('The personal label to move into the team tag set.'),
  })
  .describe(
    "Request to share one of the caller's personal labels with their team."
  );

export const promoteTagResponse = zod
  .object({
    color: zod.string().nullish(),
    displayOrder: zod.number(),
    id: zod.uuid(),
    propertyDefinitionId: zod.uuid(),
    value: zod
      .union([
        zod
          .object({
            type: zod.enum(['string']),
            value: zod
              .string()
              .describe('String value for SelectString properties'),
          })
          .describe('String value for SelectString properties'),
        zod
          .object({
            type: zod.enum(['number']),
            value: zod
              .number()
              .describe('Number value for SelectNumber properties'),
          })
          .describe('Number value for SelectNumber properties'),
      ])
      .describe(
        'The value of a property option - either a string or a number.'
      ),
  })
  .describe('Property option response (API representation).');