/*
 * Copyright 2025 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using Google.Cloud.ModelArmor.V1;
using Xunit;
using Xunit.Abstractions;

namespace ModelArmor.Samples.Tests
{
    [Collection("FloorSettingCollection")]
    public class UpdateFolderFloorSettingsTests : IClassFixture<FloorSettingFixture>
    {
        private readonly FloorSettingFixture _fixture;
        private readonly UpdateFolderFloorSettings _sample;
        private readonly ITestOutputHelper _output;

        public UpdateFolderFloorSettingsTests(FloorSettingFixture fixture, ITestOutputHelper output)
        {
            _fixture = fixture;
            _sample = new UpdateFolderFloorSettings();
            _output = output;
        }

        [Fact]
        public void UpdateFolderFloorSettingTest()
        {
            // Get folder ID from environment variable
            string folderId = _fixture.GetRequiredEnvVar("MA_FOLDER_ID");

            // Run the sample
            FloorSetting response = _sample.UpdateFolderFloorSetting(folderId);

            // Verify response
            Assert.NotNull(response);
            Assert.Equal($"folders/{folderId}/locations/global/floorSetting", response.Name);
            Assert.True(response.EnableFloorSettingEnforcement);
            Assert.Contains(
                response.FilterConfig.RaiSettings.RaiFilters,
                filter =>
                    filter.FilterType == RaiFilterType.HateSpeech
                    && filter.ConfidenceLevel == DetectionConfidenceLevel.High
            );
        }
    }
}
