import * as abortAgentMessageResponse from "./resolvers/ai/abort-agent-message-response.js";
import * as agentAttachment from "./resolvers/ai/agent-attachment.js";
import * as agentChatArgs from "./resolvers/ai/agent-chat-args.js";
import * as agentChatPayload from "./resolvers/ai/agent-chat-payload.js";
import * as agentChatResponse from "./resolvers/ai/agent-chat-response.js";
import * as agentGenerateArgs from "./resolvers/ai/agent-generate-args.js";
import * as agentMessageInput from "./resolvers/ai/agent-message-input.js";
import * as agentMessageOutput from "./resolvers/ai/agent-message-output.js";
import * as agentMessagePayload from "./resolvers/ai/agent-message-payload.js";
import * as agentRunMode from "./resolvers/ai/agent-run-mode.js";
import * as agentSessionPayload from "./resolvers/ai/agent-session-payload.js";
import * as aiUsageItem from "./resolvers/ai/ai-usage-item.js";
import * as embeddingSearchArgs from "./resolvers/ai/embedding-search.js";
import * as hybridSearchArgs from "./resolvers/ai/hybrid-search.js";
import * as sendAgentFeedbackArgs from "./resolvers/ai/send-agent-feedback-args.js";
import * as asset from "./resolvers/takeshape/assets/asset.js";
import * as assetImage from "./resolvers/takeshape/assets/asset-image.js";
import * as assetImageMeta from "./resolvers/takeshape/assets/asset-image-meta.js";
import * as assetImageParams from "./resolvers/takeshape/assets/asset-image-params.js";
import { JSON_SHAPE_NAME } from "./resolvers/takeshape/builtins/constants.js";
export function isAsset(content) {
    return content._contentTypeId === asset.shapeId || content._shapeId === asset.shapeId;
}
const ASSET_PATH = 'Hk6FQuz5';
export function getAssetS3Path(content) {
    return content[ASSET_PATH];
}
export function setAssetS3Path(content, path) {
    content[ASSET_PATH] = path;
}
export const jsonShape = {
    id: JSON_SHAPE_NAME,
    name: JSON_SHAPE_NAME,
    title: JSON_SHAPE_NAME,
    schema: {}
};
const builtInShapes = {
    [JSON_SHAPE_NAME]: jsonShape,
    TSRelationship: {
        id: 'TSRelationship',
        name: 'TSRelationship',
        title: 'Relationship',
        schema: {
            type: 'object',
            properties: {
                shapeId: {
                    type: 'string'
                },
                shapeName: {
                    type: 'string'
                },
                contentTypeId: {
                    type: 'string',
                    '@deprecationReason': 'Use shapeId instead'
                },
                id: { type: 'string' }
            },
            required: ['id']
        }
    },
    TSRelationshipArgs: {
        id: 'TSRelationshipArgs',
        name: 'TSRelationshipArgs',
        title: 'TSRelationshipArgs',
        schema: {
            type: 'object',
            properties: {
                enableLocaleFallback: {
                    type: 'boolean',
                    default: true
                },
                locale: {
                    type: 'string'
                }
            }
        }
    },
    TSColorHsl: {
        id: 'TSColorHsl',
        name: 'TSColorHsl',
        title: 'Color Hsl',
        schema: {
            type: 'object',
            properties: {
                h: { type: 'number' },
                a: { type: 'number' },
                s: { type: 'number' },
                l: { type: 'number' }
            }
        }
    },
    TSColorHsv: {
        id: 'TSColorHsv',
        name: 'TSColorHsv',
        title: 'Color Hsv',
        schema: {
            type: 'object',
            properties: {
                h: { type: 'number' },
                a: { type: 'number' },
                s: { type: 'number' },
                v: { type: 'number' }
            }
        }
    },
    TSColorRgb: {
        id: 'TSColorRgb',
        name: 'TSColorRgb',
        title: 'Color Rgb',
        schema: {
            type: 'object',
            properties: {
                a: { type: 'number' },
                b: { type: 'number' },
                r: { type: 'number' },
                g: { type: 'number' }
            }
        }
    },
    TSColor: {
        id: 'TSColor',
        name: 'TSColor',
        title: 'Color',
        schema: {
            type: 'object',
            properties: {
                hex: { type: 'string' },
                hsl: { $ref: '#/shapes/TSColorHsl/schema' },
                hsv: { $ref: '#/shapes/TSColorHsv/schema' },
                rgb: { $ref: '#/shapes/TSColorRgb/schema' }
            }
        }
    },
    TSUser: {
        id: 'TSUser',
        name: 'TSUser',
        title: 'TSUser',
        schema: {
            type: 'object',
            properties: {
                id: { type: 'string' },
                email: { type: 'string' },
                fullName: { type: 'string' },
                avatarPath: { type: 'string' }
            },
            required: ['id', 'email', 'fullName']
        }
    },
    TSWhereWildcard: {
        id: 'TSWhereWildcard',
        name: 'TSWhereWildcard',
        title: 'Where Wildcard',
        schema: {
            type: 'object',
            properties: {
                value: { type: 'string', description: 'The wildcard pattern to match.' },
                caseInsensitive: { type: 'boolean', description: 'Set to true for case-insensitive matching.' }
            },
            required: ['value']
        }
    },
    TSWhereMatchPhraseAdvanced: {
        id: 'TSWhereMatchPhraseAdvanced',
        name: 'TSWhereMatchPhraseAdvanced',
        title: 'Where Match Phrase Advanced',
        schema: {
            type: 'object',
            properties: {
                query: { type: 'string', description: 'The phrase to match.' },
                slop: {
                    type: 'integer',
                    description: 'Number of positions terms can be apart. Use to match phrases with words in between, e.g., slop: 1 allows "cool shirt" to match "cool t shirt".'
                },
                analyzer: {
                    type: 'string',
                    description: "Analyzer to use for the query. If not specified, uses the field's default analyzer."
                },
                zero_terms_query: {
                    type: 'string',
                    enum: ['none', 'all'],
                    description: "What to do if the analyzer removes all tokens. 'none' returns no results (default), 'all' matches all documents."
                },
                boost: {
                    type: 'number',
                    description: 'Boost factor to increase or decrease the relevance score of this query. Values greater than 1 increase relevance, values between 0 and 1 decrease it. Default is 1.0.'
                }
            },
            required: ['query']
        }
    },
    TSWhereMatchAdvanced: {
        id: 'TSWhereMatchAdvanced',
        name: 'TSWhereMatchAdvanced',
        title: 'Where Match Advanced',
        schema: {
            type: 'object',
            properties: {
                query: { type: 'string', description: 'The text to search for.' },
                operator: {
                    type: 'string',
                    enum: ['and', 'or'],
                    description: "Whether all terms must match ('and') or any term can match ('or', default)."
                },
                fuzziness: {
                    type: 'string',
                    description: "Allows fuzzy matching for typo tolerance. Use 'AUTO' to adjust based on term length, or 0, 1, 2 to specify edit distance."
                },
                minimum_should_match: {
                    type: 'string',
                    description: "Minimum number or percentage of terms that must match. E.g., '2' or '75%'."
                },
                analyzer: {
                    type: 'string',
                    description: "Analyzer to use for the query. If not specified, uses the field's default analyzer."
                },
                zero_terms_query: {
                    type: 'string',
                    enum: ['none', 'all'],
                    description: "What to do if the analyzer removes all tokens. 'none' returns no results (default), 'all' matches all documents."
                },
                boost: {
                    type: 'number',
                    description: 'Boost factor to increase or decrease the relevance score of this query. Values greater than 1 increase relevance, values between 0 and 1 decrease it. Default is 1.0.'
                }
            },
            required: ['query']
        }
    },
    [asset.shapeName]: {
        id: asset.shapeId,
        name: asset.shapeName,
        title: 'Asset',
        model: {
            type: 'multiple'
        },
        schema: asset.schema
    },
    [assetImageParams.shapeName]: {
        id: assetImageParams.shapeId,
        name: assetImageParams.shapeName,
        title: 'Asset Image Params',
        type: 'input',
        schema: assetImageParams.schema
    },
    [assetImage.shapeName]: {
        id: assetImage.shapeId,
        name: assetImage.shapeName,
        title: 'Asset Image',
        schema: assetImage.schema
    },
    [assetImageMeta.shapeName]: {
        id: assetImageMeta.shapeId,
        name: assetImageMeta.shapeName,
        title: 'Asset Image Meta',
        schema: assetImageMeta.schema
    },
    TSReference: {
        id: 'TSReference',
        name: 'TSReference',
        title: 'TakeShape Reference',
        schema: {
            type: 'object',
            properties: {
                _tid: {
                    type: 'string'
                },
                data: {
                    '@ref': 'TSSearchable',
                    '@resolver': {
                        name: 'takeshape:get',
                        service: 'takeshape',
                        args: {
                            ops: [{ path: 'tid', mapping: '$source._tid' }]
                        }
                    }
                }
            },
            required: ['_tid']
        }
    },
    TSEmbeddingSearchArgs: {
        id: 'TSEmbeddingSearchArgs',
        name: 'TSEmbeddingSearchArgs',
        title: 'Embedding Search Args',
        schema: embeddingSearchArgs.schema
    },
    [hybridSearchArgs.shapeName]: {
        id: hybridSearchArgs.shapeName,
        name: hybridSearchArgs.shapeName,
        title: 'Hybrid Search Args',
        schema: hybridSearchArgs.schema
    },
    [aiUsageItem.shapeName]: {
        title: 'AI Usage Item',
        id: aiUsageItem.shapeName,
        name: aiUsageItem.shapeName,
        schema: aiUsageItem.schema
    },
    [agentRunMode.shapeName]: {
        title: 'Agent Run Mode',
        id: agentRunMode.shapeName,
        name: agentRunMode.shapeName,
        schema: agentRunMode.schema
    },
    [agentGenerateArgs.shapeName]: {
        title: 'Generate Args',
        id: agentGenerateArgs.shapeName,
        name: agentGenerateArgs.shapeName,
        schema: agentGenerateArgs.shapeSchema
    },
    [agentChatArgs.shapeName]: {
        title: 'Chat Args',
        id: agentChatArgs.shapeName,
        name: agentChatArgs.shapeName,
        schema: agentChatArgs.shapeSchema
    },
    // Preserved for backward compatibility
    [agentChatResponse.shapeName]: {
        title: 'Chat Agent Response',
        id: agentChatResponse.shapeName,
        name: agentChatResponse.shapeName,
        schema: agentChatResponse.createUserShapeSchema()
    },
    [agentChatPayload.shapeName]: {
        title: 'Chat Agent Payload',
        id: agentChatPayload.shapeName,
        name: agentChatPayload.shapeName,
        schema: agentChatPayload.schema
    },
    [abortAgentMessageResponse.shapeName]: {
        title: 'Abort Agent Message Response',
        id: abortAgentMessageResponse.shapeName,
        name: abortAgentMessageResponse.shapeName,
        schema: abortAgentMessageResponse.shapeSchema
    },
    [sendAgentFeedbackArgs.shapeName]: {
        title: 'Send Agent Feedback Args',
        id: sendAgentFeedbackArgs.shapeName,
        name: sendAgentFeedbackArgs.shapeName,
        schema: sendAgentFeedbackArgs.schema
    },
    [agentMessageInput.stringInputSchema.title]: {
        title: agentMessageInput.stringInputSchema.title,
        id: agentMessageInput.stringInputSchema.title,
        name: agentMessageInput.stringInputSchema.title,
        schema: agentMessageInput.stringInputSchema
    },
    [agentMessageInput.unknownInputSchema.title]: {
        title: agentMessageInput.unknownInputSchema.title,
        id: agentMessageInput.unknownInputSchema.title,
        name: agentMessageInput.unknownInputSchema.title,
        schema: agentMessageInput.unknownInputSchema
    },
    [agentAttachment.shapeName]: {
        title: agentAttachment.shapeName,
        id: agentAttachment.shapeName,
        name: agentAttachment.shapeName,
        schema: agentAttachment.schema
    },
    [agentMessageInput.shapeName]: {
        title: agentMessageInput.shapeSchema.title,
        id: agentMessageInput.shapeSchema.title,
        name: agentMessageInput.shapeSchema.title,
        schema: agentMessageInput.shapeSchema
    },
    [agentMessageOutput.generateStateOutputSchema.title]: {
        title: agentMessageOutput.generateStateOutputSchema.title,
        id: agentMessageOutput.generateStateOutputSchema.title,
        name: agentMessageOutput.generateStateOutputSchema.title,
        schema: agentMessageOutput.generateStateOutputSchema
    },
    [agentMessageOutput.graphQLStateOutputSchema.title]: {
        title: agentMessageOutput.graphQLStateOutputSchema.title,
        id: agentMessageOutput.graphQLStateOutputSchema.title,
        name: agentMessageOutput.graphQLStateOutputSchema.title,
        schema: agentMessageOutput.graphQLStateOutputSchema
    },
    [agentMessageOutput.chatStateOutputSchema.title]: {
        title: agentMessageOutput.chatStateOutputSchema.title,
        id: agentMessageOutput.chatStateOutputSchema.title,
        name: agentMessageOutput.chatStateOutputSchema.title,
        schema: agentMessageOutput.chatStateOutputSchema
    },
    [agentMessageOutput.unknownStateOutputSchema.title]: {
        title: agentMessageOutput.unknownStateOutputSchema.title,
        id: agentMessageOutput.unknownStateOutputSchema.title,
        name: agentMessageOutput.unknownStateOutputSchema.title,
        schema: agentMessageOutput.unknownStateOutputSchema
    },
    [agentMessageOutput.shapeName]: {
        title: agentMessageOutput.shapeSchema.title,
        id: agentMessageOutput.shapeSchema.title,
        name: agentMessageOutput.shapeSchema.title,
        schema: agentMessageOutput.shapeSchema
    },
    [agentSessionPayload.shapeName]: {
        title: agentSessionPayload.shapeSchema.title,
        id: agentSessionPayload.shapeSchema.title,
        name: agentSessionPayload.shapeSchema.title,
        schema: agentSessionPayload.shapeSchema
    },
    [agentMessagePayload.shapeName]: {
        title: agentMessagePayload.shapeSchema.title,
        id: agentMessagePayload.shapeSchema.title,
        name: agentMessagePayload.shapeSchema.title,
        schema: agentMessagePayload.shapeSchema
    }
};
const staticSiteShapes = {
    TSStaticSite: {
        id: 'SITE',
        name: 'TSStaticSite',
        title: 'Static Site',
        model: {
            type: 'multiple'
        },
        schema: {
            type: 'object',
            properties: {
                title: {
                    type: 'string',
                    title: 'Title',
                    '@l10n': false,
                    minLength: 1,
                    '@mapping': 'shapedb:TsStaticSite.Ski9jLuXg'
                },
                baseUrl: {
                    type: 'string',
                    title: 'Base URL',
                    '@l10n': false,
                    minLength: 1,
                    '@mapping': 'shapedb:TsStaticSite.Bk3tNmrfE'
                },
                provider: {
                    type: 'string',
                    default: 's3',
                    title: 'Provider',
                    '@l10n': false,
                    oneOf: [
                        {
                            enum: ['s3'],
                            title: 'S3'
                        },
                        {
                            enum: ['gcs'],
                            title: 'Google Cloud Storage'
                        },
                        {
                            enum: ['ftp'],
                            title: 'FTP Client'
                        },
                        {
                            enum: ['azure'],
                            title: 'Azure Storage Account'
                        },
                        {
                            enum: ['netlify'],
                            title: 'Netlify'
                        },
                        {
                            enum: ['vercel'],
                            title: 'Vercel'
                        }
                    ],
                    '@mapping': 'shapedb:TsStaticSite.SkwbT2hqe'
                },
                idKey: {
                    type: 'string',
                    title: 'Id Key',
                    '@l10n': false,
                    minLength: 1,
                    '@mapping': 'shapedb:TsStaticSite.SyRhi8_me'
                },
                secretKey: {
                    type: 'string',
                    title: 'Secret Key',
                    '@l10n': false,
                    '@sensitive': true,
                    minLength: 1,
                    '@mapping': 'shapedb:TsStaticSite.BkIajLdXl'
                },
                destination: {
                    type: 'string',
                    title: 'Destination',
                    '@l10n': false,
                    minLength: 1,
                    '@mapping': 'shapedb:TsStaticSite.Hk6TsIdXl'
                },
                privateAcl: {
                    type: 'boolean',
                    title: 'Private ACL',
                    '@l10n': false,
                    '@mapping': 'shapedb:TsStaticSite.ByFe48wWU'
                },
                environmentVariables: {
                    type: 'array',
                    title: 'Environment Variables',
                    '@l10n': false,
                    items: {
                        $ref: '#/shapes/TSStaticSiteEnvironmentVariables/schema'
                    },
                    '@mapping': 'shapedb:TsStaticSite.9fj4UiNxY'
                },
                triggers: {
                    type: 'array',
                    title: 'Publish Triggers',
                    '@l10n': false,
                    items: {
                        $ref: '#/shapes/TSStaticSiteTriggers/schema'
                    }
                },
                templateHash: {
                    type: 'string',
                    title: 'Template Hash',
                    '@l10n': false,
                    '@mapping': 'shapedb:TsStaticSite.S1QA3GYI8'
                }
            },
            required: ['title', 'provider', 'destination']
        }
    },
    TSStaticSiteEnvironmentVariables: {
        id: '9fj4UiNxY',
        name: 'TSStaticSiteEnvironmentVariables',
        title: 'Static Site EnvironmentVariables',
        schema: {
            type: 'object',
            properties: {
                name: {
                    type: 'string',
                    title: 'Name',
                    '@mapping': 'shapedb:TsStaticSite.J8sbHgfdI'
                },
                value: {
                    type: 'string',
                    title: 'Value',
                    '@mapping': 'shapedb:TsStaticSite.ndhh88DvG'
                }
            }
        }
    },
    TSStaticSiteTriggers: {
        id: 'TSStaticSiteTriggers',
        name: 'TSStaticSiteTriggers',
        title: 'Static Site Triggers',
        schema: {
            type: 'object',
            properties: {
                contentTypeId: {
                    type: 'string',
                    title: 'Content Type'
                },
                status: {
                    type: 'string',
                    title: 'Workflow Status'
                }
            }
        }
    }
};
const builtInForms = {
    Asset: {
        default: {
            order: ['title', 'description', 'caption', 'credit', 'filename', 'path', 'mimeType', 'sourceUrl', 'uploadStatus'],
            properties: {
                title: {
                    widget: 'singleLineText'
                },
                description: {
                    widget: 'paragraphText'
                },
                caption: {
                    widget: 'wysiwygSingleLineText'
                },
                credit: {
                    widget: 'wysiwygSingleLineText'
                },
                filename: {
                    widget: 'singleLineText'
                },
                path: {
                    widget: 'singleLineText'
                },
                mimeType: {
                    widget: 'singleLineText'
                },
                sourceUrl: {
                    widget: 'singleLineText'
                },
                uploadStatus: {
                    widget: 'singleLineText'
                }
            }
        }
    }
};
const staticSiteForms = {
    TSStaticSite: {
        default: {
            order: ['title', 'provider', 'destination', 'idKey', 'secretKey', 'environmentVariables'],
            properties: {
                title: {
                    widget: 'singleLineText'
                },
                provider: {
                    widget: 'dropdown'
                },
                destination: {
                    widget: 'singleLineText',
                    instructions: 'Deployment Bucket or FTP Host'
                },
                idKey: {
                    widget: 'singleLineText',
                    instructions: 'AWS Access Key ID or Google Cloud Storage Client Email or FTP Username'
                },
                secretKey: {
                    widget: 'sensitiveField',
                    instructions: 'AWS Secret Access Key or Google Cloud Storage Private Key or FTP Password',
                    multiline: true
                },
                environmentVariables: {
                    widget: 'repeater',
                    order: ['name', 'value'],
                    properties: {
                        name: {
                            widget: 'singleLineText'
                        },
                        value: {
                            widget: 'singleLineText'
                        }
                    }
                }
            }
        },
        generalHeader: {
            order: ['title', 'provider', 'baseUrl'],
            properties: {
                title: {
                    widget: 'singleLineText'
                },
                provider: {
                    widget: 'dropdown'
                },
                baseUrl: {
                    widget: 'singleLineText'
                }
            }
        },
        generalFooter: {
            order: ['environmentVariables', 'triggers'],
            properties: {
                environmentVariables: {
                    widget: 'repeater',
                    order: ['name', 'value'],
                    properties: {
                        name: {
                            widget: 'singleLineText'
                        },
                        value: {
                            widget: 'singleLineText'
                        }
                    }
                },
                triggers: {
                    widget: 'repeater',
                    order: ['contentTypeId', 'status'],
                    preview: 'siteTriggerPreview',
                    properties: {
                        contentTypeId: {
                            widget: 'dropdown'
                        },
                        status: {
                            widget: 'dropdown'
                        }
                    }
                }
            }
        },
        s3: {
            order: ['destination', 'idKey', 'secretKey', 'privateAcl'],
            properties: {
                destination: {
                    widget: 'singleLineText',
                    instructions: 'Deployment Bucket Name'
                },
                idKey: {
                    widget: 'singleLineText',
                    instructions: 'AWS Access Key ID'
                },
                secretKey: {
                    widget: 'sensitiveField',
                    instructions: 'AWS Secret Access Key',
                    multiline: true
                },
                privateAcl: {
                    widget: 'checkbox',
                    instructions: 'Disable public access to deployed files. This is useful when fronting S3 with CloudFront or with "Block All Public Access"'
                }
            }
        },
        gcs: {
            order: ['destination', 'idKey', 'secretKey', 'privateAcl'],
            properties: {
                destination: {
                    widget: 'singleLineText',
                    instructions: 'Deployment Bucket Name'
                },
                idKey: {
                    widget: 'singleLineText',
                    instructions: 'Google Cloud Storage Client Email'
                },
                secretKey: {
                    widget: 'sensitiveField',
                    instructions: 'Google Cloud Storage Private Key',
                    multiline: true
                },
                privateAcl: {
                    widget: 'checkbox',
                    instructions: 'Disable public access to deployed files.'
                }
            }
        },
        ftp: {
            order: ['destination', 'idKey', 'secretKey'],
            properties: {
                destination: {
                    widget: 'singleLineText',
                    instructions: 'FTP Host'
                },
                idKey: {
                    widget: 'singleLineText',
                    instructions: 'FTP Username'
                },
                secretKey: {
                    widget: 'sensitiveField',
                    instructions: 'FTP Password',
                    multiline: true
                }
            }
        },
        azure: {
            order: ['destination', 'secretKey'],
            properties: {
                destination: {
                    widget: 'singleLineText',
                    instructions: 'Storage Account Name'
                },
                secretKey: {
                    widget: 'sensitiveField',
                    instructions: 'Access key',
                    multiline: true
                }
            }
        },
        netlify: {
            order: ['destination'],
            properties: {
                destination: {
                    widget: 'publishTargets',
                    itemTemplate: 'siteDropdownItem',
                    instructions: 'Choose existing or create a new site.'
                }
            }
        },
        vercel: {
            order: ['destination'],
            properties: {
                destination: {
                    widget: 'publishTargets',
                    itemTemplate: 'siteDropdownItem',
                    instructions: 'Choose existing or create a new project.'
                }
            }
        }
    }
};
export function getBuiltInShapes(options) {
    return options?.entitlements.staticSites ? { ...builtInShapes, ...staticSiteShapes } : builtInShapes;
}
export function getBuiltInForms(options) {
    return options.entitlements.staticSites ? { ...builtInForms, ...staticSiteForms } : builtInForms;
}
export const allBuiltInShapes = { ...builtInShapes, ...staticSiteShapes };
export const allBuiltInForms = { ...builtInForms, ...staticSiteForms };
