require "../src/storage.cr"

alias DSZ = DNSManager::Storage::Zone

storage = DNSManager::Storage.new "STORAGE"

user_data = DNSManager::Storage::UserData.new 1004
storage.user_data << user_data rescue nil

domain = "test.example.com"
zone = DSZ.new domain

a_record    = DSZ::A.new    "www",  600.to_u32, "127.0.0.1"
aaaa_record = DSZ::AAAA.new "www",  600.to_u32, "::1"
mx_record   = DSZ::MX.new   "mail", 600.to_u32, "127.0.0.1", 5.to_u32
spf_record  = DSZ::SPF.new  "test.example.com.", 600.to_u32, "target", "spf2lol",
                ([] of DSZ::SPF::Mechanism), DSZ::SPF::Qualifier::SoftFail

zone.resources << a_record
zone.resources << aaaa_record
zone.resources << mx_record
zone.resources << spf_record

# Add the new domain to the user.
user_data.domains << domain
storage.update_user_data user_data

# Add the new zone in the database.
storage.zones_by_domain.update_or_create domain, zone

pp! storage.user_data
puts "Zones !!!"
pp! storage.zones
storage.zones.to_a.each do |z|
	pp! z
end