package leigh.stack.dnsd;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import org.xbill.DNS.Message;
import org.xbill.DNS.Type;

import java.io.IOException;
import java.net.InetAddress;

/**
 * An emergency implementation of {@link NameStore} to meet the needs for the LEGIH&CO network following the
 * implosion of FreeIPA.
 *
 * @author Alex Leigh
 */
public class LeighCoZone implements NameStore {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(LeighCoZone.class);

    @Override
    public Message doQuery(Message request) throws IOException {
        int t = request.getQuestion().getType();
        String name = request.getQuestion().getName().toString();

        if (t == Type.A) {
            return switch (name) {
                case "b0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.16"));
                case "bungie.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.35"));
                case "db1.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.22"));
                case "db2.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.21"));
                case "dream.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.29"));
                case "ds0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.11"));
                case "esp0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.30"));
                case "fs1.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.34"));
                case "ghibli.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.44"));
                case "gitlab.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.26"));
                case "helium.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.24"));
                case "irc0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.67"));
                case "leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.51"));
                case "m3.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.68"));
                case "massive.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.28"));
                case "mctest0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.33"));
                case "moon.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.32"));
                case "mx0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.27"));
                case "mine0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.15"));
                case "n0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.14"));
                case "n1.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.59"));
                case "pixel.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.19"));
                case "slb0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.51"));
                case "ticket.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.10"));
                case "web0.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.20"));
                case "world.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.5"));
                case "zebra.leigh-co.com." -> DNSUtil.buildReply(request, InetAddress.getByName("10.52.4.17"));
                default -> null;
            };
        } else if (t == Type.PTR) {
            return switch (name) {
                case "24.4.52.10.in-addr.arpa." -> DNSUtil.buildReply(request, "helium.leigh-co.com.");
                case "67.4.52.10.in-addr.arpa." -> DNSUtil.buildReply(request, "irc0.leigh-co.com.");
                default -> null;
            };
        }
        return null;
    }
}
