# Copyright (C) 2025 Huawei Device Co., Ltd.
# 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.

import("//build/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/taihe_idl/taihe.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")

subsystem_name = "graphic"
part_name = "graphic_2d"
taihe_generated_file_path =
    "$taihe_file_path/out/$subsystem_name/$part_name/window_animation_manager"
window_animation_manager_path = "//foundation/graphic/graphic_2d/interfaces/kits/ani/window_animation_manager"

copy_taihe_idl("copy_taihe") {
  sources = [ "${window_animation_manager_path}/idl/ohos.animation.windowAnimationManager.taihe" ]
}

ohos_taihe("run_window_animation_manager_taihe") {
  taihe_generated_file_path = "$taihe_generated_file_path"
  deps = [ ":copy_taihe" ]
  outputs = [
    "$taihe_generated_file_path/src/ohos.animation.windowAnimationManager.ani.cpp",
    "$taihe_generated_file_path/src/ohos.animation.windowAnimationManager.abi.c",
  ]
}

taihe_shared_library("window_animation_manager_taihe") {
  taihe_generated_file_path = "$taihe_generated_file_path"
  subsystem_name = "$subsystem_name"
  part_name = "$part_name"
  include_dirs = [
    "include",
    "$graphic_2d_root/utils/log",
  ]

  sources = get_target_outputs(":run_window_animation_manager_taihe")

  sources += [
    "${window_animation_manager_path}/src/ani_constructor.cpp",
    "${window_animation_manager_path}/src/taihe_rs_window_animation_controller.cpp",
    "${window_animation_manager_path}/src/taihe_window_animation_finished_callback.cpp",
    "${window_animation_manager_path}/src/taihe_window_animation_utils.cpp",
    "${window_animation_manager_path}/src/window_animation_finished_callback_impl.cpp",
    "${window_animation_manager_path}/src/window_animation_manager_taihe_impl.cpp",
  ]

  deps = [
    ":run_window_animation_manager_taihe",
    "$graphic_2d_root/rosen/modules/animation/window_animation:window_animation",
    "$graphic_2d_root/rosen/modules/platform:eventhandler",
    "$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
    "$graphic_2d_root/rosen/modules/render_service_client:librender_service_client",
  ]

  if (os_level == "standard") {
    sanitize = {
      cfi = true
      cfi_cross_dso = true
      debug = false
    }
  }

  cflags = [
    "-DHILOG_ENABLE",
    "-fPIC",
    "-g3",
  ]

  external_deps = [
    "ability_runtime:ability_manager",
    "ability_runtime:runtime",
    "access_token:libaccesstoken_sdk",
    "c_utils:utils",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "input:libmmi-client",
    "ipc:ipc_core",
    "runtime_core:ani",
    "samgr:samgr_proxy",
    "window_manager:libwm",
    "window_manager:libwmutil",
    "window_manager:libwmutil_base",
    "window_manager:sms",
  ]
}

generate_static_abc("window_animation_manager_ets") {
  base_url = "$taihe_generated_file_path"
  files = [
    "$taihe_generated_file_path/@ohos.animation.windowAnimationManager.ets",
  ]
  is_boot_abc = "True"
  device_dst_file = "/system/framework/window_animation_manager_ets.abc"
  dependencies = [ ":run_window_animation_manager_taihe" ]
}

ohos_prebuilt_etc("window_animation_manager_etc") {
  source = "$target_out_dir/window_animation_manager_ets.abc"
  module_install_dir = "framework"
  part_name = "$part_name"
  subsystem_name = "$subsystem_name"
  deps = [ ":window_animation_manager_ets" ]
}

group("window_animation_manager_taihe_group") {
  deps = [
    ":window_animation_manager_etc",
    ":window_animation_manager_taihe",
  ]
}