/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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
 *
 *      http://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.
 */

package com.android.wm.shell.flicker.bubbles.utils

import android.app.Instrumentation
import android.tools.device.apphelpers.StandardAppHelper
import android.tools.traces.parsers.WindowManagerStateHelper
import android.tools.traces.surfaceflinger.LayerTraceEntry
import android.tools.traces.wm.WindowManagerState
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.helpers.SimpleAppHelper

/**
 * A helper class used in `companion object` to initialize essential properties to launch flicker
 * tests.
 */
open class FlickerPropertyInitializer {

    val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()

    val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)

    /**
     * Helper class to wait on [WindowManagerState] or [LayerTraceEntry] conditions.
     *
     * This is also used to wait for transition completes.
     */
    val wmHelper = WindowManagerStateHelper(
        instrumentation,
        clearCacheAfterParsing = false,
    )

    /**
     * Used for building the scenario.
     */
    val tapl: LauncherInstrumentation = LauncherInstrumentation()

    /**
     * The app used in flicker tests to verify with.
     */
    open val testApp: StandardAppHelper = SimpleAppHelper(instrumentation)
}