// ---------------------------------------------------------------------------
// ai-foundry-search.bicep
// Deploys an Azure AI Search service with semantic ranking enabled.
// Used for RAG (Retrieval-Augmented Generation) patterns in AI Foundry.
// ---------------------------------------------------------------------------

@description('Name of the Azure AI Search service. Must be globally unique.')
param searchName string

@description('Azure region.')
param location string = resourceGroup().location

@description('Search service pricing tier.')
@allowed(['free', 'basic', 'standard', 'standard2', 'standard3', 'storage_optimized_l1', 'storage_optimized_l2'])
param sku string = 'basic'

@description('Number of search replicas (higher = more throughput & availability).')
@minValue(1)
@maxValue(12)
param replicaCount int = 1

@description('Number of search partitions (higher = more storage & indexing throughput).')
@allowed([1, 2, 3, 4, 6, 12])
param partitionCount int = 1

@description('Semantic search pricing tier. "free" gives limited queries/month.')
@allowed(['disabled', 'free', 'standard'])
param semanticSearch string = 'free'

@description('Tags applied to all resources.')
param tags object = {}

// ---------------------------------------------------------------------------
// Azure AI Search service
// ---------------------------------------------------------------------------
resource search 'Microsoft.Search/searchServices@2024-03-01-preview' = {
  name: searchName
  location: location
  tags: tags
  sku: {
    name: sku
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    replicaCount: replicaCount
    partitionCount: partitionCount
    hostingMode: 'default'
    publicNetworkAccess: 'enabled'
    semanticSearch: semanticSearch
  }
}

// ---------------------------------------------------------------------------
// Outputs
// ---------------------------------------------------------------------------
output searchId string = search.id
output searchName string = search.name
output searchEndpoint string = 'https://${search.name}.search.windows.net'
output searchPrincipalId string = search.identity.principalId
