//
//  BlocklistOption.swift
//  dns
//
//  Created by Benjamin Erhart on 14.04.26.
//

import Foundation
import NetworkExtension

enum BlocklistOption: String, CaseIterable, Identifiable {
    case secure = "Secure"
    case securePlusAdblock = "Secure + Adblock"

    var id: String {
        switch self {
        case .secure:
            return NSLocalizedString("Secure", comment: "")

        case .securePlusAdblock:
            return NSLocalizedString("Secure + Adblock", comment: "")
        }
    }

    var enabled: Bool {
        switch self {
        case .secure:
            return true
        case .securePlusAdblock:
            return false
        }
    }

    var description: String {
        switch self {
        case .secure:
            return NSLocalizedString("Malware and phishing protection", comment: "")
        case .securePlusAdblock:
            return NSLocalizedString("Security plus ad and tracker blocking", comment: "")
        }
    }

    var title: String {
        return String(format: "%1$@: %2$@", ViewModel.title, id)
    }

    var icon: String {
        switch self {
        case .secure:
            return "shield"
        case .securePlusAdblock:
            return "shield.righthalf.filled"
        }
    }

    var server: String {
        switch self {
        case .secure:
            return "dns.sr2.uk"
        case .securePlusAdblock:
            return "dnsplus.sr2.uk"
        }
    }

    var ipv4: String {
        switch self {
        case .secure:
            return "144.76.160.194"
        case .securePlusAdblock:
            return "192.0.2.1"
        }
    }

    var ipv6: String {
        switch self {
        case .secure:
            return "2a01:4f8:2210:23ea::4"
        case .securePlusAdblock:
            return "2001:db8::1"
        }
    }

    var settings: NEDNSOverHTTPSSettings {
        let settings = NEDNSOverHTTPSSettings(servers: [ipv4, ipv6])
        settings.serverURL = URL(string: "https://\(server)/dns-query")
        settings.matchDomains = ["", "invalid"]

        return settings
    }
}
