-- PRODUCTION SCRIPT TO CONFIGURE AI ASSIST

-- EnableAskKeyhouse
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'EnableAskKeyhouse')
BEGIN
    UPDATE [dbo].[Settings]
    SET KeyValue = 'True'
    WHERE keyname = 'EnableAskKeyhouse';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('EnableAskKeyhouse', 'True');
END
GO

-- AZURE_OPENAI_RESOURCE
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'AZURE_OPENAI_RESOURCE')
BEGIN
    UPDATE [dbo].[Settings]
    SET KeyValue = 'prod-aiassist'
    WHERE keyname = 'AZURE_OPENAI_RESOURCE';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('AZURE_OPENAI_RESOURCE', 'prod-aiassist');
END
GO

-- AZURE_OPENAI_KEY
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'AZURE_OPENAI_KEY')
BEGIN
    UPDATE [dbo].[Settings]
    SET KeyValue = '6yNAuXvHymr4K4DwYerUwv754kVqj2fi6qxurF2vuzcaN0PXREXRJQQJ99BIAC5RqLJXJ3w3AAABACOGU1XK'
    WHERE keyname = 'AZURE_OPENAI_KEY';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('AZURE_OPENAI_KEY', '6yNAuXvHymr4K4DwYerUwv754kVqj2fi6qxurF2vuzcaN0PXREXRJQQJ99BIAC5RqLJXJ3w3AAABACOGU1XK');
END
GO

-- AI_API_URL
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'AI_API_URL')
BEGIN
    UPDATE [dbo].[Settings]
    SET KeyValue = 'https://prod-aiassist.openai.azure.com/'
    WHERE keyname = 'AI_API_URL';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('AI_API_URL', 'https://prod-aiassist.openai.azure.com/');
END
GO

-- AI_VERSION
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'AI_VERSION')
BEGIN    
	UPDATE [dbo].[Settings]
    SET KeyValue = '2025-01-01-preview'
    WHERE keyname = 'AI_VERSION';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('AI_VERSION', '2025-01-01-preview');
END
GO

-- AI_MODEL
IF EXISTS (SELECT TOP 1 1 FROM [dbo].[Settings] WHERE keyname = 'AI_MODEL')
BEGIN
    UPDATE [dbo].[Settings]
    SET KeyValue = 'gpt-4o-mini'
    WHERE keyname = 'AI_MODEL';
END
ELSE
BEGIN
    INSERT INTO [dbo].[Settings] (keyname, KeyValue)
    VALUES ('AI_MODEL', 'gpt-4o-mini');
 END
GO


