import * as HttpClient from "effect/unstable/http/HttpClient";
import * as S from "effect/Schema";
import * as stream from "effect/Stream";
import * as API from "../client/api.js";
import * as T from "../traits.js";
import * as C from "../category.js";
const ns = T.XmlNamespace("https://object.mediastore.amazonaws.com/doc/2017-09-01");
const svc = T.AwsApiService({
    sdkId: "MediaStore Data",
    serviceShapeName: "MediaStoreObject_20170901",
});
const auth = T.AwsAuthSigv4({ name: "mediastore" });
const ver = T.ServiceVersion("2017-09-01");
const proto = T.AwsProtocolsRestJson1();
const rules = T.EndpointResolver((p, _) => {
    const { Region, UseDualStack = false, UseFIPS = false, Endpoint } = p;
    const e = (u, p = {}, h = {}) => ({
        type: "endpoint",
        endpoint: { url: u, properties: p, headers: h },
    });
    const err = (m) => ({
        type: "error",
        message: m,
    });
    if (Endpoint != null) {
        if (UseFIPS === true) {
            return err("Invalid Configuration: FIPS and custom endpoint are not supported");
        }
        if (UseDualStack === true) {
            return err("Invalid Configuration: Dualstack and custom endpoint are not supported");
        }
        return e(Endpoint);
    }
    if (Region != null) {
        {
            const PartitionResult = _.partition(Region);
            if (PartitionResult != null && PartitionResult !== false) {
                if (UseFIPS === true && UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsFIPS") &&
                        true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://data.mediastore-fips.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("FIPS and DualStack are enabled, but this partition does not support one or both");
                }
                if (UseFIPS === true) {
                    if (_.getAttr(PartitionResult, "supportsFIPS") === true) {
                        return e(`https://data.mediastore-fips.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
                    }
                    return err("FIPS is enabled but this partition does not support FIPS");
                }
                if (UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://data.mediastore.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://data.mediastore.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const DeleteObjectRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Path: S.String.pipe(T.HttpLabel("Path")) }).pipe(T.all(ns, T.Http({ method: "DELETE", uri: "/{Path+}" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "DeleteObjectRequest",
});
export const DeleteObjectResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({}).pipe(ns)).annotate({
    identifier: "DeleteObjectResponse",
});
export const DescribeObjectRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Path: S.String.pipe(T.HttpLabel("Path")) }).pipe(T.all(ns, T.Http({ method: "HEAD", uri: "/{Path+}" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "DescribeObjectRequest",
});
export const DescribeObjectResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ETag: S.optional(S.String).pipe(T.HttpHeader("ETag")),
    ContentType: S.optional(S.String).pipe(T.HttpHeader("Content-Type")),
    ContentLength: S.optional(S.Number).pipe(T.HttpHeader("Content-Length")),
    CacheControl: S.optional(S.String).pipe(T.HttpHeader("Cache-Control")),
    LastModified: S.optional(S.Date.pipe(T.TimestampFormat("http-date"))).pipe(T.HttpHeader("Last-Modified")),
}).pipe(ns)).annotate({
    identifier: "DescribeObjectResponse",
});
export const GetObjectRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Path: S.String.pipe(T.HttpLabel("Path")),
    Range: S.optional(S.String).pipe(T.HttpHeader("Range")),
}).pipe(T.all(ns, T.Http({ method: "GET", uri: "/{Path+}" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "GetObjectRequest",
});
export const GetObjectResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Body: S.optional(T.StreamingOutput).pipe(T.HttpPayload()),
    CacheControl: S.optional(S.String).pipe(T.HttpHeader("Cache-Control")),
    ContentRange: S.optional(S.String).pipe(T.HttpHeader("Content-Range")),
    ContentLength: S.optional(S.Number).pipe(T.HttpHeader("Content-Length")),
    ContentType: S.optional(S.String).pipe(T.HttpHeader("Content-Type")),
    ETag: S.optional(S.String).pipe(T.HttpHeader("ETag")),
    LastModified: S.optional(S.Date.pipe(T.TimestampFormat("http-date"))).pipe(T.HttpHeader("Last-Modified")),
    StatusCode: S.Number.pipe(T.HttpResponseCode()),
}).pipe(ns)).annotate({
    identifier: "GetObjectResponse",
});
export const ListItemsRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Path: S.optional(S.String).pipe(T.HttpQuery("Path")),
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("MaxResults")),
    NextToken: S.optional(S.String).pipe(T.HttpQuery("NextToken")),
}).pipe(T.all(ns, T.Http({ method: "GET", uri: "/" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListItemsRequest",
});
export const ItemType = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const Item = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Name: S.optional(S.String),
    Type: S.optional(ItemType),
    ETag: S.optional(S.String),
    LastModified: S.optional(S.Date.pipe(T.TimestampFormat("epoch-seconds"))),
    ContentType: S.optional(S.String),
    ContentLength: S.optional(S.Number),
})).annotate({ identifier: "Item" });
export const ItemList = /*@__PURE__*/ /*#__PURE__*/ S.Array(Item);
export const ListItemsResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Items: S.optional(ItemList),
    NextToken: S.optional(S.String),
}).pipe(ns)).annotate({
    identifier: "ListItemsResponse",
});
export const StorageClass = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const UploadAvailability = /*@__PURE__*/ /*#__PURE__*/ S.String;
export const PutObjectRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Body: T.StreamingInput.pipe(T.HttpPayload()),
    Path: S.String.pipe(T.HttpLabel("Path")),
    ContentType: S.optional(S.String).pipe(T.HttpHeader("Content-Type")),
    CacheControl: S.optional(S.String).pipe(T.HttpHeader("Cache-Control")),
    StorageClass: S.optional(StorageClass).pipe(T.HttpHeader("x-amz-storage-class")),
    UploadAvailability: S.optional(UploadAvailability).pipe(T.HttpHeader("x-amz-upload-availability")),
}).pipe(T.all(ns, T.Http({ method: "PUT", uri: "/{Path+}" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "PutObjectRequest",
});
export const PutObjectResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ContentSHA256: S.optional(S.String),
    ETag: S.optional(S.String),
    StorageClass: S.optional(StorageClass),
}).pipe(ns)).annotate({
    identifier: "PutObjectResponse",
});
//# Errors
export class ContainerNotFoundException extends S.TaggedErrorClass()("ContainerNotFoundException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class InternalServerError extends S.TaggedErrorClass()("InternalServerError", { Message: S.optional(S.String) }) {
}
export class ObjectNotFoundException extends S.TaggedErrorClass()("ObjectNotFoundException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class RequestedRangeNotSatisfiableException extends S.TaggedErrorClass()("RequestedRangeNotSatisfiableException", { Message: S.optional(S.String) }) {
}
/**
 * Deletes an object at the specified path.
 */
export const deleteObject = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteObjectRequest,
    output: DeleteObjectResponse,
    errors: [
        ContainerNotFoundException,
        InternalServerError,
        ObjectNotFoundException,
    ],
}));
/**
 * Gets the headers for an object at the specified path.
 */
export const describeObject = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DescribeObjectRequest,
    output: DescribeObjectResponse,
    errors: [
        ContainerNotFoundException,
        InternalServerError,
        ObjectNotFoundException,
    ],
}));
/**
 * Downloads the object at the specified path. If the object’s upload availability is set to `streaming`, AWS Elemental MediaStore downloads the object even if it’s still uploading the object.
 */
export const getObject = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetObjectRequest,
    output: GetObjectResponse,
    errors: [
        ContainerNotFoundException,
        InternalServerError,
        ObjectNotFoundException,
        RequestedRangeNotSatisfiableException,
    ],
}));
/**
 * Provides a list of metadata entries about folders and objects in the specified
 * folder.
 */
export const listItems = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListItemsRequest,
    output: ListItemsResponse,
    errors: [ContainerNotFoundException, InternalServerError],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        pageSize: "MaxResults",
    },
}));
/**
 * Uploads an object to the specified path. Object sizes are limited to 25 MB for standard upload availability and 10 MB for streaming upload availability.
 */
export const putObject = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: PutObjectRequest,
    output: PutObjectResponse,
    errors: [ContainerNotFoundException, InternalServerError],
}));
//# sourceMappingURL=mediastore-data.js.map