import { describe, it } from "vitest";
import { fileURLToPath } from "url";
import * as path from "node:path";
import * as fs from "node:fs";
import { ProjectSkeleton } from "@opendaw/studio-adapters";
import { Option, panic, Terminable } from "@opendaw/lib-std";
import { Xml } from "@opendaw/lib-xml";
import { FileReferenceSchema } from "@opendaw/lib-dawproject";
import { DawProjectExporter } from "./DawProjectExporter";
describe("DawProjectExport", () => {
    it("export", async () => {
        const __dirname = path.dirname(fileURLToPath(import.meta.url));
        const projectPath = "../../../../../test-files/all-devices.od";
        const buffer = fs.readFileSync(path.join(__dirname, projectPath));
        const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
        const sampleManager = new class {
            record(_loader) {
                throw new Error("Method not implemented.");
            }
            getOrCreate(format) {
                return new class {
                    data = Option.None;
                    peaks = Option.None;
                    uuid = format;
                    state = { type: "progress", progress: 0.0 };
                    meta = Option.None;
                    invalidate() { throw new Error("Method not implemented."); }
                    subscribe(_observer) {
                        return Terminable.Empty;
                    }
                };
            }
            remove(_uuid) { return panic("Method not implemented."); }
            invalidate(_uuid) { return panic("Method not implemented."); }
            register(_uuid) { return Terminable.Empty; }
        };
        const skeleton = ProjectSkeleton.decode(arrayBuffer);
        const schema = DawProjectExporter.write(skeleton, sampleManager, {
            write: (path, buffer) => {
                console.debug(`store ${buffer.byteLength} bytes at ${path}`);
                return Xml.element({ path, external: false }, FileReferenceSchema);
            }
        });
        // console.dir(schema, {depth: Number.MAX_SAFE_INTEGER})
        console.debug(Xml.pretty(Xml.toElement("Project", schema)));
    });
});
