package com.pdf.base.impl

import com.compdfkit.core.document.CPDFDocument
import com.pdf.base.interfaces.OpenDocumentCallback


typealias OpenDocumentSuccess = (CPDFDocument) -> Unit
typealias OpenDocumentFail = (CPDFDocument.PDFDocumentError) -> Unit
typealias DocumentIsEncrypt = (CPDFDocument) -> Unit

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/11/18
 * description: 打开文档监听默认实现
 */
class NormalOpenDocumentCallback : OpenDocumentCallback {

    private var success : OpenDocumentSuccess? = null
    private var fail : OpenDocumentFail? = null
    private var isEncrypt : DocumentIsEncrypt? = null

    override fun success(cPdfDocument: CPDFDocument) {
        success?.invoke(cPdfDocument)
    }

    override fun fail(error: CPDFDocument.PDFDocumentError) {
        fail?.invoke(error)
    }

    override fun isEncrypt(cPdfDocument: CPDFDocument) {
        isEncrypt?.invoke(cPdfDocument)
    }

    fun success(success: OpenDocumentSuccess){
        this.success = success
    }

    fun fail(fail : OpenDocumentFail){
        this.fail = fail
    }

    fun isEncrypt(isEncrypt: DocumentIsEncrypt){
        this.isEncrypt = isEncrypt
    }

}