#include <chrono>
#include <vector>

#include "SkString.h"
#include "common.h"

//region ohos
// The Fusion renderer uses OHRender instead of Ganesh and OHRender is built
// without SkSL, Skottie and several advanced typeface APIs. Keep the complete
// m150 native ABI linkable and return deterministic unsupported values here.
// This turns missing-symbol/IrLinkageError crashes into ordinary null results
// (or a descriptive RuntimeEffect compilation error).

static void deleteUnsupportedBackendTexture(KNativePointer) {
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendTexture__1nGetFinalizer() {
    return reinterpret_cast<KNativePointer>(&deleteUnsupportedBackendTexture);
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_BackendTexture__1nMakeGL
  (KInt, KInt, KBoolean, KInt, KInt, KInt) {
    return nullptr;
}

SKIKO_EXPORT void org_jetbrains_skia_BackendTexture__1nGLTextureParametersModified
  (KNativePointer) {
}

SKIKO_EXPORT KNativePointer BackendRenderTarget_nMakeMetal
  (KInt, KInt, KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer BackendRenderTarget_MakeDirect3D
  (KInt, KInt, KNativePointer, KInt, KInt, KInt) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeMetal
  (KNativePointer, KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_DirectContext__1nMakeDirect3D
  (KNativePointer, KNativePointer, KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlush
  (KNativePointer, KNativePointer) {
}

SKIKO_EXPORT KLong org_jetbrains_skia_DirectContext__1nGetResourceCacheLimit
  (KNativePointer) {
    return 0;
}

SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nSetResourceCacheLimit
  (KNativePointer, KLong) {
}

SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nFlushAndSubmit
  (KNativePointer, KNativePointer, KBoolean) {
}

SKIKO_EXPORT void org_jetbrains_skia_DirectContext__1nReset
  (KNativePointer, KInt) {
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRenderTarget
  (KNativePointer, KBoolean, KInt, KInt, KInt, KInt, KNativePointer,
   KInt, KInt, KInteropPointer, KBoolean) {
    return nullptr;
}

struct UnsupportedRuntimeEffectResult {
    SkString error = SkString("RuntimeEffect is not supported by OHRender Fusion Renderer");
};

static KNativePointer makeUnsupportedRuntimeEffectResult() {
    return reinterpret_cast<KNativePointer>(new UnsupportedRuntimeEffectResult());
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1nMakeShader
  (KNativePointer, KNativePointer, KNativePointerArray, KInt, KFloat*) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1nMakeBlender
  (KNativePointer, KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1nMakeForShader
  (KInteropPointer) {
    return makeUnsupportedRuntimeEffectResult();
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1nMakeForColorFilter
  (KInteropPointer) {
    return makeUnsupportedRuntimeEffectResult();
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1nMakeForBlender
  (KInteropPointer) {
    return makeUnsupportedRuntimeEffectResult();
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1Result_nGetPtr
  (KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeEffect__1Result_nGetError
  (KNativePointer ptr) {
    auto* result = reinterpret_cast<UnsupportedRuntimeEffectResult*>(ptr);
    return result == nullptr ? nullptr : reinterpret_cast<KNativePointer>(&result->error);
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeEffect__1Result_nDestroy
  (KNativePointer ptr) {
    delete reinterpret_cast<UnsupportedRuntimeEffectResult*>(ptr);
}

static void deleteUnsupportedRuntimeShaderBuilder(KNativePointer) {
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeShaderBuilder__1nGetFinalizer() {
    return reinterpret_cast<KNativePointer>(&deleteUnsupportedRuntimeShaderBuilder);
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeShaderBuilder__1nMakeFromRuntimeEffect
  (KNativePointer) {
    return nullptr;
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformInt
  (KNativePointer, KInteropPointer, KInt) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformInt2
  (KNativePointer, KInteropPointer, KInt, KInt) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformInt3
  (KNativePointer, KInteropPointer, KInt, KInt, KInt) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformInt4
  (KNativePointer, KInteropPointer, KInt, KInt, KInt, KInt) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloat
  (KNativePointer, KInteropPointer, KFloat) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloat2
  (KNativePointer, KInteropPointer, KFloat, KFloat) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloat3
  (KNativePointer, KInteropPointer, KFloat, KFloat, KFloat) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloat4
  (KNativePointer, KInteropPointer, KFloat, KFloat, KFloat, KFloat) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloatArray
  (KNativePointer, KInteropPointer, KFloat*, int32_t) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloatMatrix22
  (KNativePointer, KInteropPointer, KFloat*) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloatMatrix33
  (KNativePointer, KInteropPointer, KFloat*) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nUniformFloatMatrix44
  (KNativePointer, KInteropPointer, KFloat*) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nChildShader
  (KNativePointer, KInteropPointer, KNativePointer) {
}

SKIKO_EXPORT void org_jetbrains_skia_RuntimeShaderBuilder__1nChildColorFilter
  (KNativePointer, KInteropPointer, KNativePointer) {
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_RuntimeShaderBuilder__1nMakeShader
  (KNativePointer, KFloat*) {
    return nullptr;
}

SKIKO_EXPORT void org_jetbrains_skia_Typeface__1nGetUTF32Glyphs
  (KNativePointer, KInt*, KInt count, KShort* result) {
    for (KInt index = 0; index < count; ++index) result[index] = 0;
}

SKIKO_EXPORT KShort org_jetbrains_skia_Typeface__1nGetUTF32Glyph
  (KNativePointer, KInt) {
    return 0;
}

SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nGetGlyphsCount
  (KNativePointer) {
    return 0;
}

SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nGetTablesCount
  (KNativePointer) {
    return 0;
}

SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nGetTableTagsCount
  (KNativePointer) {
    return 0;
}

SKIKO_EXPORT void org_jetbrains_skia_Typeface__1nGetTableTags
  (KNativePointer, KInt*, KInt) {
}

SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nGetTableSize
  (KNativePointer, KInt) {
    return 0;
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Typeface__1nGetTableData
  (KNativePointer, KInt) {
    return nullptr;
}

SKIKO_EXPORT KInt org_jetbrains_skia_Typeface__1nGetUnitsPerEm
  (KNativePointer) {
    return 0;
}

SKIKO_EXPORT bool org_jetbrains_skia_Typeface__1nGetKerningPairAdjustments
  (KNativePointer, KInteropPointer, KInt, KInt*) {
    return false;
}

SKIKO_EXPORT KInteropPointer org_jetbrains_skia_Typeface__1nGetFamilyNames
  (KNativePointer) {
    return reinterpret_cast<KInteropPointer>(new std::vector<KInteropPointer>());
}

SKIKO_EXPORT void org_jetbrains_skia_Typeface__1nGetBounds
  (KNativePointer, KFloat* bounds) {
    bounds[0] = 0;
    bounds[1] = 0;
    bounds[2] = 0;
    bounds[3] = 0;
}

SKIKO_EXPORT KLong org_jetbrains_skia_OHRenderNode__1nGetCurrentTimeMicros() {
    return static_cast<KLong>(std::chrono::duration_cast<std::chrono::microseconds>(
        std::chrono::steady_clock::now().time_since_epoch()
    ).count());
}

SKIKO_EXPORT KInt skikobridge_napi_get_system_theme() {
    return 0;
}
//endregion
