#include "SkPath.h"
#include "SkRRect.h"
#include "common.h"

//region ohos
// m150 exposes immutable Path factories backed by newer SkSpan-based Skia APIs.
// OHRender uses the older pointer/count overloads, so keep the Kotlin ABI and
// translate only the native construction calls here.
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromRaw
  (KFloat* ptsArray, KInt ptsCount,
   KByte* verbsArray, KInt verbsCount,
   KFloat* conicWeightsArray, KInt conicWeightsCount,
   KInt fillType, KBoolean isVolatile) {
    SkPath path = SkPath::Make(
        reinterpret_cast<const SkPoint*>(ptsArray), ptsCount,
        reinterpret_cast<const uint8_t*>(verbsArray), verbsCount,
        conicWeightsArray, conicWeightsCount,
        static_cast<SkPathFillType>(fillType),
        isVolatile
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromRect
  (KFloat left, KFloat top, KFloat right, KFloat bottom,
   KInt fillType, KInt direction, KInt startIndex) {
    SkPath path = SkPath::Rect(
        SkRect::MakeLTRB(left, top, right, bottom),
        static_cast<SkPathDirection>(direction),
        startIndex
    );
    path.setFillType(static_cast<SkPathFillType>(fillType));
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromOval
  (KFloat left, KFloat top, KFloat right, KFloat bottom,
   KInt direction, KInt startIndex) {
    SkPath path = SkPath::Oval(
        SkRect::MakeLTRB(left, top, right, bottom),
        static_cast<SkPathDirection>(direction),
        startIndex
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromCircle
  (KFloat centerX, KFloat centerY, KFloat radius, KInt direction) {
    SkPath path = SkPath::Circle(
        centerX,
        centerY,
        radius,
        static_cast<SkPathDirection>(direction)
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromRRect
  (KFloat* radiiArray,
   KFloat left, KFloat top, KFloat right, KFloat bottom,
   KInt direction, KInt startIndex) {
    SkRRect rrect;
    rrect.setRectRadii(
        SkRect::MakeLTRB(left, top, right, bottom),
        reinterpret_cast<const SkVector*>(radiiArray)
    );
    SkPath path = SkPath::RRect(
        rrect,
        static_cast<SkPathDirection>(direction),
        startIndex
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromRRectXY
  (KFloat left, KFloat top, KFloat right, KFloat bottom,
   KFloat rx, KFloat ry, KInt direction) {
    SkPath path = SkPath::RRect(
        SkRect::MakeLTRB(left, top, right, bottom),
        rx,
        ry,
        static_cast<SkPathDirection>(direction)
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}

SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromPolygon
  (KFloat* ptsArray, KInt ptsCount,
   KBoolean isClosed, KInt fillType, KBoolean isVolatile) {
    SkPath path = SkPath::Polygon(
        reinterpret_cast<const SkPoint*>(ptsArray), ptsCount,
        isClosed,
        static_cast<SkPathFillType>(fillType),
        isVolatile
    );
    return reinterpret_cast<KNativePointer>(new SkPath(path));
}
//endregion
