import type { AttributeType, CollectionRef, DictionaryMetaType, DocumentMetaType, Entity, Meta, State } from '.'; /** * Типы сущностей у которых есть метаданные */ export type MetadataMetaType = DocumentMetaType | DictionaryMetaType; export type MetadataMeta = { meta: { /** `https://api.moysklad.ru/api/remap/1.2/entity/product/metadata` */ href: `https://${string}/api/remap/1.2/entity/${T}/metadata`; mediaType: 'application/json'; }; }; export type AttributeMetadata = Entity<'attributemetadata'> & { /** Наименование пользовательского поля */ readonly name: string; readonly required: boolean; readonly show: boolean; } & (T extends 'customentity' ? { /** Тип значения пользовательского поля */ readonly type: T; readonly customEntityMeta: Meta<'customentitymetadata'>; } : { /** Тип значения пользовательского поля */ readonly type: T; }); export type DocumentMetadata = MetadataMeta & { attributes: CollectionRef<'attributemetadata'>; states: State[]; createShared: boolean; }; export type DictionaryMetadata = MetadataMeta & { attributes: CollectionRef<'attributemetadata'>; createShared: boolean; } & (T extends 'counterparty' ? { states: State[]; } : {}); export type Metadata = T extends DocumentMetaType ? DocumentMetadata : T extends DictionaryMetaType ? T extends 'project' | 'store' | 'product' | 'counterparty' ? DictionaryMetadata : MetadataMeta : never;