import * as HttpClient from "effect/unstable/http/HttpClient";
import * as redacted from "effect/Redacted";
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";
import { SensitiveString } from "../sensitive.js";
const svc = T.AwsApiService({
    sdkId: "CloudFront KeyValueStore",
    serviceShapeName: "CloudFrontKeyValueStore",
});
const auth = T.AwsAuthSigv4({ name: "cloudfront-keyvaluestore" });
const ver = T.ServiceVersion("2022-07-26");
const proto = T.AwsProtocolsRestJson1();
const rules = T.EndpointResolver((p, _) => {
    const { KvsARN, Region, 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,
    });
    const _p0 = () => ({
        authSchemes: [
            {
                name: "sigv4a",
                signingName: "cloudfront-keyvaluestore",
                signingRegionSet: ["*"],
            },
        ],
    });
    if (UseFIPS === false) {
        if (KvsARN != null) {
            {
                const parsedArn = _.parseArn(KvsARN);
                if (parsedArn != null && parsedArn !== false) {
                    if (_.getAttr(parsedArn, "service") === "cloudfront") {
                        if (_.getAttr(parsedArn, "region") === "") {
                            {
                                const arnType = _.getAttr(parsedArn, "resourceId[0]");
                                if (arnType != null && arnType !== false) {
                                    if (!(arnType === "")) {
                                        if (arnType === "key-value-store") {
                                            if (_.getAttr(parsedArn, "partition") === "aws") {
                                                if (Region != null) {
                                                    {
                                                        const partitionResult = _.partition(Region);
                                                        if (partitionResult != null &&
                                                            partitionResult !== false) {
                                                            if (_.getAttr(partitionResult, "name") ===
                                                                `${_.getAttr(parsedArn, "partition")}`) {
                                                                if (Endpoint != null) {
                                                                    {
                                                                        const url = _.parseURL(Endpoint);
                                                                        if (url != null && url !== false) {
                                                                            return e(`${_.getAttr(url, "scheme")}://${_.getAttr(parsedArn, "accountId")}.${_.getAttr(url, "authority")}${_.getAttr(url, "path")}`, _p0(), {});
                                                                        }
                                                                    }
                                                                    return err("Provided endpoint is not a valid URL");
                                                                }
                                                                return e(`https://${_.getAttr(parsedArn, "accountId")}.cloudfront-kvs.global.api.aws`, _p0(), {});
                                                            }
                                                            return err(`Client was configured for partition \`${_.getAttr(partitionResult, "name")}\` but Kvs ARN has \`${_.getAttr(parsedArn, "partition")}\``);
                                                        }
                                                    }
                                                }
                                                if (Endpoint != null) {
                                                    {
                                                        const url = _.parseURL(Endpoint);
                                                        if (url != null && url !== false) {
                                                            return e(`${_.getAttr(url, "scheme")}://${_.getAttr(parsedArn, "accountId")}.${_.getAttr(url, "authority")}${_.getAttr(url, "path")}`, _p0(), {});
                                                        }
                                                    }
                                                    return err("Provided endpoint is not a valid URL");
                                                }
                                                return e(`https://${_.getAttr(parsedArn, "accountId")}.cloudfront-kvs.global.api.aws`, _p0(), {});
                                            }
                                            return err(`CloudFront-KeyValueStore is not supported in partition \`${_.getAttr(parsedArn, "partition")}\``);
                                        }
                                        return err(`ARN resource type is invalid. Expected \`key-value-store\`, found: \`${arnType}\``);
                                    }
                                    return err("No resource type found in the KVS ARN. Resource type must be `key-value-store`.");
                                }
                            }
                            return err("No resource type found in the KVS ARN. Resource type must be `key-value-store`.");
                        }
                        return err(`Provided ARN must be a global resource ARN. Found: \`${_.getAttr(parsedArn, "region")}\``);
                    }
                    return err(`Provided ARN is not a valid CloudFront Service ARN. Found: \`${_.getAttr(parsedArn, "service")}\``);
                }
            }
            return err("KVS ARN must be a valid ARN");
        }
        return err("KVS ARN must be provided to use this service");
    }
    return err("Invalid Configuration: FIPS is not supported with CloudFront-KeyValueStore.");
});
export const DeleteKeyRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
    Key: S.String.pipe(T.HttpLabel("Key")),
    IfMatch: S.String.pipe(T.HttpHeader("If-Match")),
}).pipe(T.all(T.Http({
    method: "DELETE",
    uri: "/key-value-stores/{KvsARN}/keys/{Key}",
}), svc, auth, proto, ver, rules))).annotate({
    identifier: "DeleteKeyRequest",
});
export const DeleteKeyResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ItemCount: S.Number,
    TotalSizeInBytes: S.Number,
    ETag: S.String.pipe(T.HttpHeader("ETag")),
})).annotate({
    identifier: "DeleteKeyResponse",
});
export const DescribeKeyValueStoreRequest = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
}).pipe(T.all(T.Http({ method: "GET", uri: "/key-value-stores/{KvsARN}" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "DescribeKeyValueStoreRequest",
});
export const DescribeKeyValueStoreResponse = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ItemCount: S.Number,
    TotalSizeInBytes: S.Number,
    KvsARN: S.String,
    Created: S.Date.pipe(T.TimestampFormat("epoch-seconds")),
    ETag: S.String.pipe(T.HttpHeader("ETag")),
    LastModified: S.optional(S.Date.pipe(T.TimestampFormat("epoch-seconds"))),
    Status: S.optional(S.String),
    FailureReason: S.optional(S.String),
})).annotate({
    identifier: "DescribeKeyValueStoreResponse",
});
export const GetKeyRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
    Key: S.String.pipe(T.HttpLabel("Key")),
}).pipe(T.all(T.Http({ method: "GET", uri: "/key-value-stores/{KvsARN}/keys/{Key}" }), svc, auth, proto, ver, rules))).annotate({ identifier: "GetKeyRequest" });
export const GetKeyResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Key: S.String,
    Value: SensitiveString,
    ItemCount: S.Number,
    TotalSizeInBytes: S.Number,
})).annotate({ identifier: "GetKeyResponse" });
export const ListKeysRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
    NextToken: S.optional(S.String).pipe(T.HttpQuery("NextToken")),
    MaxResults: S.optional(S.Number).pipe(T.HttpQuery("MaxResults")),
}).pipe(T.all(T.Http({ method: "GET", uri: "/key-value-stores/{KvsARN}/keys" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "ListKeysRequest",
});
export const ListKeysResponseListItem = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Key: S.String, Value: SensitiveString })).annotate({
    identifier: "ListKeysResponseListItem",
});
export const ListKeysResponseList = /*@__PURE__*/ /*#__PURE__*/ S.Array(ListKeysResponseListItem);
export const ListKeysResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    NextToken: S.optional(S.String),
    Items: S.optional(ListKeysResponseList),
})).annotate({
    identifier: "ListKeysResponse",
});
export const PutKeyRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Key: S.String.pipe(T.HttpLabel("Key")),
    Value: SensitiveString,
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
    IfMatch: S.String.pipe(T.HttpHeader("If-Match")),
}).pipe(T.all(T.Http({ method: "PUT", uri: "/key-value-stores/{KvsARN}/keys/{Key}" }), svc, auth, proto, ver, rules))).annotate({ identifier: "PutKeyRequest" });
export const PutKeyResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ItemCount: S.Number,
    TotalSizeInBytes: S.Number,
    ETag: S.String.pipe(T.HttpHeader("ETag")),
})).annotate({ identifier: "PutKeyResponse" });
export const PutKeyRequestListItem = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Key: S.String, Value: SensitiveString })).annotate({
    identifier: "PutKeyRequestListItem",
});
export const PutKeyRequestsList = /*@__PURE__*/ /*#__PURE__*/ S.Array(PutKeyRequestListItem);
export const DeleteKeyRequestListItem = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({ Key: S.String })).annotate({
    identifier: "DeleteKeyRequestListItem",
});
export const DeleteKeyRequestsList = /*@__PURE__*/ /*#__PURE__*/ S.Array(DeleteKeyRequestListItem);
export const UpdateKeysRequest = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    KvsARN: S.String.pipe(T.HttpLabel("KvsARN"), T.ContextParam("KvsARN")),
    IfMatch: S.String.pipe(T.HttpHeader("If-Match")),
    Puts: S.optional(PutKeyRequestsList),
    Deletes: S.optional(DeleteKeyRequestsList),
}).pipe(T.all(T.Http({ method: "POST", uri: "/key-value-stores/{KvsARN}/keys" }), svc, auth, proto, ver, rules))).annotate({
    identifier: "UpdateKeysRequest",
});
export const UpdateKeysResponse = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    ItemCount: S.Number,
    TotalSizeInBytes: S.Number,
    ETag: S.String.pipe(T.HttpHeader("ETag")),
})).annotate({
    identifier: "UpdateKeysResponse",
});
//# Errors
export class AccessDeniedException extends S.TaggedErrorClass()("AccessDeniedException", { Message: S.optional(S.String) }).pipe(C.withAuthError) {
}
export class ConflictException extends S.TaggedErrorClass()("ConflictException", { Message: S.optional(S.String) }).pipe(C.withConflictError) {
}
export class InternalServerException extends S.TaggedErrorClass()("InternalServerException", { Message: S.optional(S.String) }).pipe(C.withServerError) {
}
export class ResourceNotFoundException extends S.TaggedErrorClass()("ResourceNotFoundException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class ServiceQuotaExceededException extends S.TaggedErrorClass()("ServiceQuotaExceededException", { Message: S.optional(S.String) }).pipe(C.withQuotaError) {
}
export class ValidationException extends S.TaggedErrorClass()("ValidationException", { Message: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
/**
 * Deletes the key value pair specified by the key.
 */
export const deleteKey = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DeleteKeyRequest,
    output: DeleteKeyResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
        ServiceQuotaExceededException,
        ValidationException,
    ],
}));
/**
 * Returns metadata information about Key Value Store.
 */
export const describeKeyValueStore = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: DescribeKeyValueStoreRequest,
    output: DescribeKeyValueStoreResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
    ],
}));
/**
 * Returns a key value pair.
 */
export const getKey = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: GetKeyRequest,
    output: GetKeyResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
    ],
}));
/**
 * Returns a list of key value pairs.
 */
export const listKeys = /*@__PURE__*/ /*#__PURE__*/ API.makePaginated(() => ({
    input: ListKeysRequest,
    output: ListKeysResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
        ValidationException,
    ],
    pagination: {
        inputToken: "NextToken",
        outputToken: "NextToken",
        items: "Items",
        pageSize: "MaxResults",
    },
}));
/**
 * Creates a new key value pair or replaces the value of an existing key.
 */
export const putKey = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: PutKeyRequest,
    output: PutKeyResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
        ServiceQuotaExceededException,
        ValidationException,
    ],
}));
/**
 * Puts or Deletes multiple key value pairs in a single, all-or-nothing operation.
 */
export const updateKeys = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: UpdateKeysRequest,
    output: UpdateKeysResponse,
    errors: [
        AccessDeniedException,
        ConflictException,
        InternalServerException,
        ResourceNotFoundException,
        ServiceQuotaExceededException,
        ValidationException,
    ],
}));
//# sourceMappingURL=cloudfront-keyvaluestore.js.map