package org.openfact.ubl;

import org.openfact.models.OpenfactSession;
import org.openfact.models.OrganizationModel;
import org.openfact.models.ubl.CreditNoteModel;
import org.openfact.models.ubl.DebitNoteModel;
import org.openfact.models.ubl.InvoiceModel;
import org.w3c.dom.Document;

import com.helger.ubl21.UBL21Reader;
import com.helger.ubl21.UBL21Writer;

import oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType;

public class DefaultUblProvider implements UblProvider {

    protected OpenfactSession session;

    public DefaultUblProvider(OpenfactSession session) {
        this.session = session;
    }

    @Override
    public void close() {
        // TODO Auto-generated method stub

    }

    @Override
    public Document getDocument(OrganizationModel organization, InvoiceModel invoice) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Document getDocument(OrganizationModel organization, CreditNoteModel creditNote) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Document getDocument(OrganizationModel organization, DebitNoteModel debitNote) {
        // TODO Auto-generated method stub
        return null;
    }

}

@@ -20,16 +20,75 @@
 t.ubl;%0A%0A
+import javax.xml.datatype.DatatypeConfigurationException;%0A%0A
 import o
@@ -301,32 +301,78 @@
 l.InvoiceModel;%0A
+import org.openfact.models.utils.ModelToType;%0A
 import org.w3c.d
@@ -418,53 +418,170 @@
 BL21
-Reader;%0Aimport com.helger.ubl21.UBL21Writer;%0A
+Writer;%0A%0Aimport oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType;%0Aimport oasis.names.specification.ubl.schema.xsd.debitnote_21.DebitNoteType;
 %0Aimp
@@ -708,20 +708,17 @@
 ider %7B%0A%0A
-    
+%09
 protecte
@@ -745,20 +745,17 @@
 ssion;%0A%0A
-    
+%09
 public D
@@ -799,24 +799,18 @@
 sion) %7B%0A
-        
+%09%09
 this.ses
@@ -825,27 +825,21 @@
 ession;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Overrid
@@ -836,28 +836,25 @@
 %0A%09@Override%0A
-    
+%09
 public void 
@@ -867,63 +867,47 @@
 ) %7B%0A
-        // TODO Auto-generated method stub%0A%0A    %7D%0A%0A    
+%09%09System.out.println(%22close...%22);%0A%09%7D%0A%0A%09
 @Ove
@@ -904,36 +904,33 @@
 %0A%09%7D%0A%0A%09@Override%0A
-    
+%09
 public Document 
@@ -1001,59 +1001,211 @@
 ) %7B%0A
-        // TODO Auto-generated method stub%0A        
+%09%09try %7B%0A%09%09%09InvoiceType invoiceType = ModelToType.toType(invoice);%0A%09%09%09return UBL21Writer.invoice().getAsDocument(invoiceType);%0A%09%09%7D catch (DatatypeConfigurationException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09
 retu
@@ -1209,35 +1209,29 @@
 eturn null;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Override%0A  
@@ -1220,36 +1220,33 @@
 %0A%09%7D%0A%0A%09@Override%0A
-    
+%09
 public Document 
@@ -1323,59 +1323,226 @@
 ) %7B%0A
-        // TODO Auto-generated method stub%0A        
+%09%09try %7B%0A%09%09%09CreditNoteType creditNoteType = ModelToType.toType(creditNote);%0A%09%09%09return UBL21Writer.creditNote().getAsDocument(creditNoteType);%0A%09%09%7D catch (DatatypeConfigurationException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09
 retu
@@ -1554,19 +1554,13 @@
 ll;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Ove
@@ -1565,20 +1565,17 @@
 verride%0A
-    
+%09
 public D
@@ -1658,59 +1658,221 @@
 ) %7B%0A
-        // TODO Auto-generated method stub%0A        
+%09%09try %7B%0A%09%09%09DebitNoteType debitNoteType = ModelToType.toType(debitNote);%0A%09%09%09return UBL21Writer.debitNote().getAsDocument(debitNoteType);%0A%09%09%7D catch (DatatypeConfigurationException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09
 retu
@@ -1884,12 +1884,9 @@
 ll;%0A
-    
+%09
 %7D%0A%0A%7D

update ubl