// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "../_dnt.polyfills.js";
import { Runtime } from "../runtimes/mod.js";
import { aws } from "../wit.js";
import { t } from "../index.js";
export class S3Runtime extends Runtime {
    constructor(options) {
        const id = aws.registerS3Runtime(options);
        super(id);
        Object.defineProperty(this, "hostSecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "regionSecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "accessKeySecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "secretKeySecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "pathStyleSecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this.hostSecret = options.hostSecret;
        this.regionSecret = options.regionSecret;
        this.accessKeySecret = options.accessKeySecret;
        this.secretKeySecret = options.secretKeySecret;
        this.pathStyleSecret = options.pathStyleSecret;
    }
    /** create a function to presign an S3 GetObject request */
    presignGet(params) {
        const { bucket, expirySecs } = params;
        const mat = {
            _id: aws.s3PresignGet(this._id, params),
            bucket,
            expirySecs,
        };
        return t.func(t.struct({ path: t.string() }), t.uri(), mat);
    }
    /** create a function to presign an S3 PutObject request */
    presignPut(params) {
        const { bucket, expirySecs, contentType } = params;
        const mat = {
            _id: aws.s3PresignPut(this._id, params),
            bucket,
            expirySecs,
            contentType,
        };
        return t.func(t.struct({ length: t.integer(), path: t.string() }), t.uri(), mat);
    }
    /**
     * create a function to list objects in a bucket
     */
    list(bucket) {
        const mat = {
            _id: aws.s3List(this._id, bucket),
            bucket,
        };
        return t.func(t.struct({ path: t.string().optional() }), t.struct({
            keys: t.list(t.struct({ key: t.string(), size: t.integer() })),
            prefix: t.list(t.string()),
        }), mat);
    }
    /** create a function for a file upload */
    upload(bucket, overrideFileType) {
        const fileType = overrideFileType ?? t.file();
        const mat = {
            _id: aws.s3Upload(this._id, bucket),
            bucket,
        };
        return t.func(t.struct({ file: fileType, path: t.string().optional() }), t.boolean(), mat);
    }
    /** create a function for multiple file uploads */
    uploadAll(bucket, overrideFileType) {
        const fileType = overrideFileType ?? t.file();
        const mat = {
            _id: aws.s3UploadAll(this._id, bucket),
            bucket,
        };
        return t.func(t.struct({
            prefix: t.string().optional({ defaultItem: "" }),
            files: t.list(fileType),
        }), t.boolean(), mat);
    }
}
