// Generated by Lisette bindgen. DO NOT EDIT.

use std::collections::HashMap;
use std::sync::LazyLock;

use crate::Target;

static GO_STDLIB_COMMON: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("archive/tar", include_str!("../typedefs/archive/tar.d.lis")),
        ("archive/zip", include_str!("../typedefs/archive/zip.d.lis")),
        ("bufio", include_str!("../typedefs/bufio.d.lis")),
        ("bytes", include_str!("../typedefs/bytes.d.lis")),
        ("cmp", include_str!("../typedefs/cmp.d.lis")),
        (
            "compress/bzip2",
            include_str!("../typedefs/compress/bzip2.d.lis"),
        ),
        (
            "compress/flate",
            include_str!("../typedefs/compress/flate.d.lis"),
        ),
        (
            "compress/gzip",
            include_str!("../typedefs/compress/gzip.d.lis"),
        ),
        (
            "compress/lzw",
            include_str!("../typedefs/compress/lzw.d.lis"),
        ),
        (
            "compress/zlib",
            include_str!("../typedefs/compress/zlib.d.lis"),
        ),
        (
            "container/heap",
            include_str!("../typedefs/container/heap.d.lis"),
        ),
        (
            "container/list",
            include_str!("../typedefs/container/list.d.lis"),
        ),
        (
            "container/ring",
            include_str!("../typedefs/container/ring.d.lis"),
        ),
        ("context", include_str!("../typedefs/context.d.lis")),
        ("crypto", include_str!("../typedefs/crypto.d.lis")),
        ("crypto/aes", include_str!("../typedefs/crypto/aes.d.lis")),
        (
            "crypto/cipher",
            include_str!("../typedefs/crypto/cipher.d.lis"),
        ),
        ("crypto/des", include_str!("../typedefs/crypto/des.d.lis")),
        ("crypto/dsa", include_str!("../typedefs/crypto/dsa.d.lis")),
        ("crypto/ecdh", include_str!("../typedefs/crypto/ecdh.d.lis")),
        (
            "crypto/ecdsa",
            include_str!("../typedefs/crypto/ecdsa.d.lis"),
        ),
        (
            "crypto/ed25519",
            include_str!("../typedefs/crypto/ed25519.d.lis"),
        ),
        (
            "crypto/elliptic",
            include_str!("../typedefs/crypto/elliptic.d.lis"),
        ),
        (
            "crypto/fips140",
            include_str!("../typedefs/crypto/fips140.d.lis"),
        ),
        ("crypto/hkdf", include_str!("../typedefs/crypto/hkdf.d.lis")),
        ("crypto/hmac", include_str!("../typedefs/crypto/hmac.d.lis")),
        ("crypto/md5", include_str!("../typedefs/crypto/md5.d.lis")),
        (
            "crypto/mlkem",
            include_str!("../typedefs/crypto/mlkem.d.lis"),
        ),
        (
            "crypto/pbkdf2",
            include_str!("../typedefs/crypto/pbkdf2.d.lis"),
        ),
        ("crypto/rand", include_str!("../typedefs/crypto/rand.d.lis")),
        ("crypto/rc4", include_str!("../typedefs/crypto/rc4.d.lis")),
        ("crypto/rsa", include_str!("../typedefs/crypto/rsa.d.lis")),
        ("crypto/sha1", include_str!("../typedefs/crypto/sha1.d.lis")),
        (
            "crypto/sha256",
            include_str!("../typedefs/crypto/sha256.d.lis"),
        ),
        ("crypto/sha3", include_str!("../typedefs/crypto/sha3.d.lis")),
        (
            "crypto/sha512",
            include_str!("../typedefs/crypto/sha512.d.lis"),
        ),
        (
            "crypto/subtle",
            include_str!("../typedefs/crypto/subtle.d.lis"),
        ),
        ("crypto/tls", include_str!("../typedefs/crypto/tls.d.lis")),
        ("crypto/x509", include_str!("../typedefs/crypto/x509.d.lis")),
        (
            "crypto/x509/pkix",
            include_str!("../typedefs/crypto/x509/pkix.d.lis"),
        ),
        (
            "database/sql",
            include_str!("../typedefs/database/sql.d.lis"),
        ),
        (
            "database/sql/driver",
            include_str!("../typedefs/database/sql/driver.d.lis"),
        ),
        (
            "debug/buildinfo",
            include_str!("../typedefs/debug/buildinfo.d.lis"),
        ),
        ("debug/dwarf", include_str!("../typedefs/debug/dwarf.d.lis")),
        ("debug/elf", include_str!("../typedefs/debug/elf.d.lis")),
        ("debug/gosym", include_str!("../typedefs/debug/gosym.d.lis")),
        ("debug/macho", include_str!("../typedefs/debug/macho.d.lis")),
        ("debug/pe", include_str!("../typedefs/debug/pe.d.lis")),
        (
            "debug/plan9obj",
            include_str!("../typedefs/debug/plan9obj.d.lis"),
        ),
        ("embed", include_str!("../typedefs/embed.d.lis")),
        ("encoding", include_str!("../typedefs/encoding.d.lis")),
        (
            "encoding/ascii85",
            include_str!("../typedefs/encoding/ascii85.d.lis"),
        ),
        (
            "encoding/asn1",
            include_str!("../typedefs/encoding/asn1.d.lis"),
        ),
        (
            "encoding/base32",
            include_str!("../typedefs/encoding/base32.d.lis"),
        ),
        (
            "encoding/base64",
            include_str!("../typedefs/encoding/base64.d.lis"),
        ),
        (
            "encoding/binary",
            include_str!("../typedefs/encoding/binary.d.lis"),
        ),
        (
            "encoding/csv",
            include_str!("../typedefs/encoding/csv.d.lis"),
        ),
        (
            "encoding/gob",
            include_str!("../typedefs/encoding/gob.d.lis"),
        ),
        (
            "encoding/hex",
            include_str!("../typedefs/encoding/hex.d.lis"),
        ),
        (
            "encoding/json",
            include_str!("../typedefs/encoding/json.d.lis"),
        ),
        (
            "encoding/pem",
            include_str!("../typedefs/encoding/pem.d.lis"),
        ),
        (
            "encoding/xml",
            include_str!("../typedefs/encoding/xml.d.lis"),
        ),
        ("errors", include_str!("../typedefs/errors.d.lis")),
        ("expvar", include_str!("../typedefs/expvar.d.lis")),
        ("flag", include_str!("../typedefs/flag.d.lis")),
        ("fmt", include_str!("../typedefs/fmt.d.lis")),
        ("go/ast", include_str!("../typedefs/go/ast.d.lis")),
        ("go/build", include_str!("../typedefs/go/build.d.lis")),
        (
            "go/build/constraint",
            include_str!("../typedefs/go/build/constraint.d.lis"),
        ),
        ("go/constant", include_str!("../typedefs/go/constant.d.lis")),
        ("go/doc", include_str!("../typedefs/go/doc.d.lis")),
        (
            "go/doc/comment",
            include_str!("../typedefs/go/doc/comment.d.lis"),
        ),
        ("go/format", include_str!("../typedefs/go/format.d.lis")),
        ("go/importer", include_str!("../typedefs/go/importer.d.lis")),
        ("go/parser", include_str!("../typedefs/go/parser.d.lis")),
        ("go/printer", include_str!("../typedefs/go/printer.d.lis")),
        ("go/scanner", include_str!("../typedefs/go/scanner.d.lis")),
        ("go/token", include_str!("../typedefs/go/token.d.lis")),
        ("go/types", include_str!("../typedefs/go/types.d.lis")),
        ("go/version", include_str!("../typedefs/go/version.d.lis")),
        ("hash", include_str!("../typedefs/hash.d.lis")),
        (
            "hash/adler32",
            include_str!("../typedefs/hash/adler32.d.lis"),
        ),
        ("hash/crc32", include_str!("../typedefs/hash/crc32.d.lis")),
        ("hash/crc64", include_str!("../typedefs/hash/crc64.d.lis")),
        ("hash/fnv", include_str!("../typedefs/hash/fnv.d.lis")),
        (
            "hash/maphash",
            include_str!("../typedefs/hash/maphash.d.lis"),
        ),
        ("html", include_str!("../typedefs/html.d.lis")),
        (
            "html/template",
            include_str!("../typedefs/html/template.d.lis"),
        ),
        ("image", include_str!("../typedefs/image.d.lis")),
        ("image/color", include_str!("../typedefs/image/color.d.lis")),
        (
            "image/color/palette",
            include_str!("../typedefs/image/color/palette.d.lis"),
        ),
        ("image/draw", include_str!("../typedefs/image/draw.d.lis")),
        ("image/gif", include_str!("../typedefs/image/gif.d.lis")),
        ("image/jpeg", include_str!("../typedefs/image/jpeg.d.lis")),
        ("image/png", include_str!("../typedefs/image/png.d.lis")),
        (
            "index/suffixarray",
            include_str!("../typedefs/index/suffixarray.d.lis"),
        ),
        ("io", include_str!("../typedefs/io.d.lis")),
        ("io/fs", include_str!("../typedefs/io/fs.d.lis")),
        ("io/ioutil", include_str!("../typedefs/io/ioutil.d.lis")),
        ("iter", include_str!("../typedefs/iter.d.lis")),
        ("log", include_str!("../typedefs/log.d.lis")),
        ("log/slog", include_str!("../typedefs/log/slog.d.lis")),
        ("log/syslog", include_str!("../typedefs/log/syslog.d.lis")),
        ("maps", include_str!("../typedefs/maps.d.lis")),
        ("math", include_str!("../typedefs/math.d.lis")),
        ("math/big", include_str!("../typedefs/math/big.d.lis")),
        ("math/bits", include_str!("../typedefs/math/bits.d.lis")),
        ("math/cmplx", include_str!("../typedefs/math/cmplx.d.lis")),
        ("math/rand", include_str!("../typedefs/math/rand.d.lis")),
        (
            "math/rand/v2",
            include_str!("../typedefs/math/rand/v2.d.lis"),
        ),
        ("mime", include_str!("../typedefs/mime.d.lis")),
        (
            "mime/multipart",
            include_str!("../typedefs/mime/multipart.d.lis"),
        ),
        (
            "mime/quotedprintable",
            include_str!("../typedefs/mime/quotedprintable.d.lis"),
        ),
        ("net", include_str!("../typedefs/net.d.lis")),
        ("net/http", include_str!("../typedefs/net/http.d.lis")),
        (
            "net/http/cgi",
            include_str!("../typedefs/net/http/cgi.d.lis"),
        ),
        (
            "net/http/cookiejar",
            include_str!("../typedefs/net/http/cookiejar.d.lis"),
        ),
        (
            "net/http/fcgi",
            include_str!("../typedefs/net/http/fcgi.d.lis"),
        ),
        (
            "net/http/httptest",
            include_str!("../typedefs/net/http/httptest.d.lis"),
        ),
        (
            "net/http/httptrace",
            include_str!("../typedefs/net/http/httptrace.d.lis"),
        ),
        (
            "net/http/httputil",
            include_str!("../typedefs/net/http/httputil.d.lis"),
        ),
        (
            "net/http/pprof",
            include_str!("../typedefs/net/http/pprof.d.lis"),
        ),
        ("net/mail", include_str!("../typedefs/net/mail.d.lis")),
        ("net/netip", include_str!("../typedefs/net/netip.d.lis")),
        ("net/rpc", include_str!("../typedefs/net/rpc.d.lis")),
        (
            "net/rpc/jsonrpc",
            include_str!("../typedefs/net/rpc/jsonrpc.d.lis"),
        ),
        ("net/smtp", include_str!("../typedefs/net/smtp.d.lis")),
        (
            "net/textproto",
            include_str!("../typedefs/net/textproto.d.lis"),
        ),
        ("net/url", include_str!("../typedefs/net/url.d.lis")),
        ("os/signal", include_str!("../typedefs/os/signal.d.lis")),
        ("os/user", include_str!("../typedefs/os/user.d.lis")),
        ("path", include_str!("../typedefs/path.d.lis")),
        ("plugin", include_str!("../typedefs/plugin.d.lis")),
        ("reflect", include_str!("../typedefs/reflect.d.lis")),
        ("regexp", include_str!("../typedefs/regexp.d.lis")),
        (
            "regexp/syntax",
            include_str!("../typedefs/regexp/syntax.d.lis"),
        ),
        (
            "runtime/coverage",
            include_str!("../typedefs/runtime/coverage.d.lis"),
        ),
        (
            "runtime/debug",
            include_str!("../typedefs/runtime/debug.d.lis"),
        ),
        (
            "runtime/metrics",
            include_str!("../typedefs/runtime/metrics.d.lis"),
        ),
        (
            "runtime/pprof",
            include_str!("../typedefs/runtime/pprof.d.lis"),
        ),
        (
            "runtime/race",
            include_str!("../typedefs/runtime/race.d.lis"),
        ),
        (
            "runtime/trace",
            include_str!("../typedefs/runtime/trace.d.lis"),
        ),
        ("slices", include_str!("../typedefs/slices.d.lis")),
        ("sort", include_str!("../typedefs/sort.d.lis")),
        ("strconv", include_str!("../typedefs/strconv.d.lis")),
        ("strings", include_str!("../typedefs/strings.d.lis")),
        ("structs", include_str!("../typedefs/structs.d.lis")),
        ("sync", include_str!("../typedefs/sync.d.lis")),
        ("sync/atomic", include_str!("../typedefs/sync/atomic.d.lis")),
        ("testing", include_str!("../typedefs/testing.d.lis")),
        (
            "testing/fstest",
            include_str!("../typedefs/testing/fstest.d.lis"),
        ),
        (
            "testing/iotest",
            include_str!("../typedefs/testing/iotest.d.lis"),
        ),
        (
            "testing/quick",
            include_str!("../typedefs/testing/quick.d.lis"),
        ),
        (
            "testing/slogtest",
            include_str!("../typedefs/testing/slogtest.d.lis"),
        ),
        (
            "testing/synctest",
            include_str!("../typedefs/testing/synctest.d.lis"),
        ),
        (
            "text/scanner",
            include_str!("../typedefs/text/scanner.d.lis"),
        ),
        (
            "text/tabwriter",
            include_str!("../typedefs/text/tabwriter.d.lis"),
        ),
        (
            "text/template",
            include_str!("../typedefs/text/template.d.lis"),
        ),
        (
            "text/template/parse",
            include_str!("../typedefs/text/template/parse.d.lis"),
        ),
        ("time", include_str!("../typedefs/time.d.lis")),
        ("time/tzdata", include_str!("../typedefs/time/tzdata.d.lis")),
        ("unicode", include_str!("../typedefs/unicode.d.lis")),
        (
            "unicode/utf16",
            include_str!("../typedefs/unicode/utf16.d.lis"),
        ),
        (
            "unicode/utf8",
            include_str!("../typedefs/unicode/utf8.d.lis"),
        ),
        ("unique", include_str!("../typedefs/unique.d.lis")),
        ("unsafe", include_str!("../typedefs/unsafe.d.lis")),
        ("weak", include_str!("../typedefs/weak.d.lis")),
    ])
});

static GO_STDLIB_LINUX_AMD64: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("os", include_str!("../typedefs/os_linux_amd64.d.lis")),
        (
            "os/exec",
            include_str!("../typedefs/os/exec_linux_amd64.d.lis"),
        ),
        (
            "path/filepath",
            include_str!("../typedefs/path/filepath_linux_amd64.d.lis"),
        ),
        (
            "runtime",
            include_str!("../typedefs/runtime_linux_amd64.d.lis"),
        ),
        (
            "syscall",
            include_str!("../typedefs/syscall_linux_amd64.d.lis"),
        ),
    ])
});

static GO_STDLIB_LINUX_ARM64: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("os", include_str!("../typedefs/os_linux_amd64.d.lis")),
        (
            "os/exec",
            include_str!("../typedefs/os/exec_linux_amd64.d.lis"),
        ),
        (
            "path/filepath",
            include_str!("../typedefs/path/filepath_linux_amd64.d.lis"),
        ),
        (
            "runtime",
            include_str!("../typedefs/runtime_linux_arm64.d.lis"),
        ),
        (
            "syscall",
            include_str!("../typedefs/syscall_linux_arm64.d.lis"),
        ),
    ])
});

static GO_STDLIB_DARWIN_AMD64: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("os", include_str!("../typedefs/os_darwin_amd64.d.lis")),
        (
            "os/exec",
            include_str!("../typedefs/os/exec_linux_amd64.d.lis"),
        ),
        (
            "path/filepath",
            include_str!("../typedefs/path/filepath_linux_amd64.d.lis"),
        ),
        (
            "runtime",
            include_str!("../typedefs/runtime_darwin_amd64.d.lis"),
        ),
        (
            "syscall",
            include_str!("../typedefs/syscall_darwin_amd64.d.lis"),
        ),
    ])
});

static GO_STDLIB_DARWIN_ARM64: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("os", include_str!("../typedefs/os_darwin_amd64.d.lis")),
        (
            "os/exec",
            include_str!("../typedefs/os/exec_linux_amd64.d.lis"),
        ),
        (
            "path/filepath",
            include_str!("../typedefs/path/filepath_linux_amd64.d.lis"),
        ),
        (
            "runtime",
            include_str!("../typedefs/runtime_darwin_arm64.d.lis"),
        ),
        (
            "syscall",
            include_str!("../typedefs/syscall_darwin_arm64.d.lis"),
        ),
    ])
});

static GO_STDLIB_WINDOWS_AMD64: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from([
        ("os", include_str!("../typedefs/os_windows_amd64.d.lis")),
        (
            "os/exec",
            include_str!("../typedefs/os/exec_windows_amd64.d.lis"),
        ),
        (
            "path/filepath",
            include_str!("../typedefs/path/filepath_windows_amd64.d.lis"),
        ),
        (
            "runtime",
            include_str!("../typedefs/runtime_windows_amd64.d.lis"),
        ),
        (
            "syscall",
            include_str!("../typedefs/syscall_windows_amd64.d.lis"),
        ),
    ])
});

static GO_STDLIB_PACKAGE_TARGETS: LazyLock<HashMap<&str, &[(&str, &str)]>> = LazyLock::new(|| {
    HashMap::from([(
        "log/syslog",
        &[
            ("linux", "amd64"),
            ("linux", "arm64"),
            ("darwin", "amd64"),
            ("darwin", "arm64"),
        ][..],
    )])
});

pub fn get_go_stdlib_typedef(package: &str, target: Target) -> Option<&'static str> {
    if !is_available_on(package, target) {
        return None;
    }
    if let Some(source) = lookup_in_overlay(target, package) {
        return Some(source);
    }
    GO_STDLIB_COMMON.get(package).copied()
}

pub fn get_go_stdlib_packages(target: Target) -> Vec<&'static str> {
    let mut packages: Vec<&'static str> = GO_STDLIB_COMMON
        .keys()
        .copied()
        .filter(|pkg| is_available_on(pkg, target))
        .collect();
    if let Some(overlay) = overlay_for(target) {
        packages.extend(overlay.keys().copied());
    }
    packages.sort();
    packages
}

pub fn get_go_stdlib_package_targets(
    package: &str,
) -> Option<&'static [(&'static str, &'static str)]> {
    GO_STDLIB_PACKAGE_TARGETS.get(package).copied()
}

fn is_available_on(package: &str, target: Target) -> bool {
    match GO_STDLIB_PACKAGE_TARGETS.get(package) {
        Some(targets) => targets
            .iter()
            .any(|(goos, goarch)| *goos == target.goos && *goarch == target.goarch),
        None => true,
    }
}

fn lookup_in_overlay(target: Target, package: &str) -> Option<&'static str> {
    overlay_for(target).and_then(|overlay| overlay.get(package).copied())
}

fn overlay_for(target: Target) -> Option<&'static HashMap<&'static str, &'static str>> {
    match (target.goos, target.goarch) {
        ("linux", "amd64") => Some(&GO_STDLIB_LINUX_AMD64),
        ("linux", "arm64") => Some(&GO_STDLIB_LINUX_ARM64),
        ("darwin", "amd64") => Some(&GO_STDLIB_DARWIN_AMD64),
        ("darwin", "arm64") => Some(&GO_STDLIB_DARWIN_ARM64),
        ("windows", "amd64") => Some(&GO_STDLIB_WINDOWS_AMD64),
        _ => None,
    }
}
