import Foundation

struct GenericPage {

    let header: PageHeader

    let additionalFooter: String

    let insertedContent: (inout String) -> Void

    init(header: PageHeader,
         additionalFooter: String,
         insertedContent: @escaping (inout String) -> Void) {
        self.header = header
        self.additionalFooter = additionalFooter
        self.insertedContent = insertedContent
    }
    
    var content: String {
        var result = ""
        header.populate(&result) // Opens <html><body><main>
        result += "\n"
        insertedContent(&result)
        result += "</main>\n" // Close <main>
        result += additionalFooter
        result += "</body></html>" // Close <body><html>
        return result
    }
}
