module APIGeneration

using Base64
using ..AWSExceptions
using GitHub
using HTTP
using JSON: JSON
using Mocking
using OrderedCollections: LittleDict, OrderedDict

const AUTO_GENERATED_SIGNATURE = "This file is auto-generated by AWS.jl"
const PKG_DIR = abspath(joinpath(@__DIR__, "..", ".."))
const HIGH_LEVEL_SERVICES_DIR = joinpath(PKG_DIR, "src", "services")
const LOW_LEVEL_SERVICES_FILE = joinpath(PKG_DIR, "src", "AWSServices.jl")

include("utilities.jl")
include("high_level.jl")
include("low_level.jl")

"""
    parse_aws_metadata()

Generate low-level and high-level Julia wrappers for each AWS service definition found in
[`aws-sdk-js` GitHub Repository](https://github.com/aws/aws-sdk-js/tree/master/apis).

Low-level API wrappers are defined in `$(relpath(LOW_LEVEL_SERVICES_FILE, PKG_DIR))` and
high-level API wrappers are each defined separate files within the directory
`$(relpath(HIGH_LEVEL_SERVICES_DIR, PKG_DIR))`.
"""
function parse_aws_metadata()
    auth = GitHub.authenticate(ENV["GITHUB_AUTH"])

    service_files = _get_service_files(auth)

    _generate_low_level_wrappers(service_files, auth)
    _generate_high_level_wrapper(service_files, auth)

    return nothing
end

end
