# Forward unknown queries to Docker's embedded DNS for service name resolution,
# with Cloudflare as fallback for external names.
# Bind to our static IP to avoid conflict with Docker's DNS proxy on 127.0.0.11.
. {
    bind 172.16.238.100
    forward . 127.0.0.11 1.1.1.1
}

# Zones configuration
webapp.com {
    bind 172.16.238.100
    template IN A {
        match "^webapp\.com\.$"
        answer "{{ .Name }} 60 IN A 203.0.0.1"
        fallthrough
    }

    template IN CNAME {
        match "^stage-site\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CNAME sites.localhost."
        fallthrough
    }

    template IN CNAME {
        match "^stage-function\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CNAME cname.localhost."
        fallthrough
    }

    template IN CNAME {
        match "^stage\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CNAME cname.localhost."
        fallthrough
    }

    template IN CNAME {
        match "^stage-wrong-cname\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CNAME cname-wrong.tests.appwrite.io."
        fallthrough
    }

    template IN A {
        match "^stage-wrong-caa\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN A 203.0.0.1"
        fallthrough
    }

    template IN CAA {
        match "^stage-wrong-caa\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CAA 0 issue \"unknown-issuer.org\""
        fallthrough
    }


    template IN A {
        match "^stage-correct-caa\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN A 203.0.0.1"
        fallthrough
    }

    template IN CAA {
        match "^stage-correct-caa\.webapp\.com\.$"
        answer "{{ .Name }} 60 IN CAA 0 issue \"digicert.com\""
        fallthrough
    }

    forward . 1.1.1.1
}

# Zones configuration
wrong-a-webapp.com {
    bind 172.16.238.100
    template IN A {
        match "^wrong-a-webapp\.com\.$"
        answer "{{ .Name }} 60 IN A 203.0.0.5"
        fallthrough
    }
}