
struct ModelCommand: CommandProcessor {

    static let commandType: CommandType = .model

    let content: Content

    let results: PageGenerationResults

    let language: ContentLanguage

    init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
        self.content = content
        self.results = results
        self.language = language
    }

    /**
     Format: `![model](<file>)`
     */
    func process(_ arguments: [String], markdown: Substring) -> String {
        guard arguments.count == 1 else {
            invalid(markdown)
            return ""
        }
        let fileId = arguments[0]
        guard fileId.hasSuffix(".glb") else {
            invalid(markdown)
            return ""
        }

        guard let file = content.file(fileId) else {
            results.missing(file: fileId, source: "Model command")
            return ""
        }
        results.require(file: file)
        results.require(header: .modelViewer)

        let description = file.localized(in: language)
        return ModelViewer(file: file.absoluteUrl, description: description).content
    }


}
