import Foundation

final class GeneralSettings: ObservableObject {

    @Published
    var url: String

    @Published
    var linkPreviewImageWidth: Int

    @Published
    var linkPreviewImageHeight: Int

    init(url: String, linkPreviewImageWidth: Int, linkPreviewImageHeight: Int) {
        self.url = url
        self.linkPreviewImageWidth = linkPreviewImageWidth
        self.linkPreviewImageHeight = linkPreviewImageHeight
    }
}

extension GeneralSettings {

    convenience init(data: Data) {
        self.init(
            url: data.url,
            linkPreviewImageWidth: data.linkPreviewImageWidth,
            linkPreviewImageHeight: data.linkPreviewImageHeight)
    }

    var data: Data {
        .init(
            url: url,
            linkPreviewImageWidth: linkPreviewImageWidth,
            linkPreviewImageHeight: linkPreviewImageHeight)
    }

    struct Data: Codable {
        let url: String
        let linkPreviewImageWidth: Int
        let linkPreviewImageHeight: Int
    }
}
