import { execa } from "execa";
import { singleton } from "./fable_modules/fable-library-js.4.26.0/AsyncBuilder.js";
import { awaitPromise } from "./fable_modules/fable-library-js.4.26.0/Async.js";
import { writeFile, readFile, access } from "fs/promises";
import * as fs from "fs";
import { class_type } from "./fable_modules/fable-library-js.4.26.0/Reflection.js";

export const NodeApi_execa = execa;

function NodeApi_callExeca(executable, args) {
    return singleton.Delay(() => singleton.Bind(awaitPromise(NodeApi_execa(executable, args)), (_arg) => {
        const result = _arg;
        return singleton.Return([result.stdout, result.stderr, result.exitCode]);
    }));
}

class NodeApi_Api {
    constructor() {
    }
    isReadable(path) {
        return awaitPromise(access(path, fs.constants.R_OK));
    }
    readFile(path) {
        return awaitPromise(readFile(path, "utf8"));
    }
    isWritable(path) {
        return awaitPromise(access(path, fs.constants.W_OK));
    }
    writeFile(path, content) {
        return awaitPromise(writeFile(path, content, "utf8"));
    }
    get cargoExecutable() {
        return (process.platform === "win32") ? "cargo.exe" : "cargo";
    }
    exec(args) {
        const this$ = this;
        return NodeApi_callExeca(this$.cargoExecutable, args);
    }
}

function NodeApi_Api_$reflection() {
    return class_type("SemanticReleaseCargo.ExternalApi.NodeApi.Api", undefined, NodeApi_Api);
}

function NodeApi_Api_$ctor() {
    return new NodeApi_Api();
}

export const NodeApi_api = NodeApi_Api_$ctor();

