<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using ONIT.VismaNetApi.Models;

namespace ONIT.VismaNetApi.Lib.Data
{
	public class CustomerInvoiceData : BaseCrudDataClass<CustomerInvoice>
	{
        /// <summary>
		///     This constructor is called by the client to create the data source.
		/// </summary>
		internal CustomerInvoiceData(VismaNetAuthorization auth) : base(auth)
		{
		    ApiControllerUri = VismaNetControllers.CustomerInvoice;
		}

	    protected CustomerInvoiceData() : base(null)
	    {
            ApiControllerUri = VismaNetControllers.CustomerInvoice;
	        
	    }

        /// <summary>
        /// Fetches all invoices for a customer
        /// </summary>
        /// <param name="customerNumber">customerCd</param>
        /// <returns></returns>
        public async Task<List<CustomerInvoice>> ForCustomer(string customerNumber)
        {
            return await VismaNetApiHelper.FetchInvoicesForCustomerCd(customerNumber, Authorization);
        }
        
        /// <summary>
        /// Fetches all invoices for a given customer
        /// </summary>
        /// <param name="customer">An instance of Customer</param>
        /// <returns></returns>
        public async Task<List<CustomerInvoice>> ForCustomer(Customer customer)
        {
            return await ForCustomer(customer.number);
        }
        
	    public async Task<VismaActionResult> ReleaseInvoice(CustomerInvoice invoice)
	    {
	        return await VismaNetApiHelper.InvoiceAction(invoice.GetIdentificator(), "release", Authorization);
	    }

        public async Task<VismaActionResult> ReverseInvoice(CustomerInvoice invoice)
        {
            return await VismaNetApiHelper.InvoiceAction(invoice.GetIdentificator(), "reverse", Authorization);
        }

	    public async Task<string> AddAttachmentToInvoice(string invoiceNumber, string content, string fileName)
	    {
	        using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
	        {
	            return await AddAttachmentToInvoice(invoiceNumber, memoryStream, fileName);
	        }
	    }
        public async Task<string> AddAttachmentToInvoice(string invoiceNumber, Stream stream, string fileName)
	    {
            if(stream == default(Stream))
                throw new ArgumentNullException(nameof(stream), "Stream is missing");
            if(string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
                throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
	        return await VismaNetApiHelper.AddAttachmentToInvoice(Authorization, invoiceNumber, stream, fileName);
	    }

        public async Task<Stream> PrintInvoice(CustomerInvoice invoice)
        {
            return await VismaNetApiHelper.InvoicePrint(invoice.GetIdentificator(), Authorization);
        }

	    public async Task<bool> Delete(string invoiceNumber)<commit_msg>Fixed attachment upload<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using ONIT.VismaNetApi.Models;

namespace ONIT.VismaNetApi.Lib.Data
{
	public class CustomerInvoiceData : BaseCrudDataClass<CustomerInvoice>
	{
        /// <summary>
		///     This constructor is called by the client to create the data source.
		/// </summary>
		internal CustomerInvoiceData(VismaNetAuthorization auth) : base(auth)
		{
		    ApiControllerUri = VismaNetControllers.CustomerInvoice;
		}

	    protected CustomerInvoiceData() : base(null)
	    {
            ApiControllerUri = VismaNetControllers.CustomerInvoice;
	        
	    }

        /// <summary>
        /// Fetches all invoices for a customer
        /// </summary>
        /// <param name="customerNumber">customerCd</param>
        /// <returns></returns>
        public async Task<List<CustomerInvoice>> ForCustomer(string customerNumber)
        {
            return await VismaNetApiHelper.FetchInvoicesForCustomerCd(customerNumber, Authorization);
        }
        
        /// <summary>
        /// Fetches all invoices for a given customer
        /// </summary>
        /// <param name="customer">An instance of Customer</param>
        /// <returns></returns>
        public async Task<List<CustomerInvoice>> ForCustomer(Customer customer)
        {
            return await ForCustomer(customer.number);
        }
        
	    public async Task<VismaActionResult> ReleaseInvoice(CustomerInvoice invoice)
	    {
	        return await VismaNetApiHelper.InvoiceAction(invoice.GetIdentificator(), "release", Authorization);
	    }

        public async Task<VismaActionResult> ReverseInvoice(CustomerInvoice invoice)
        {
            return await VismaNetApiHelper.InvoiceAction(invoice.GetIdentificator(), "reverse", Authorization);
        }

	    public async Task<string> AddAttachmentToInvoice(string invoiceNumber, string content, string fileName)
	    {
	        var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(content));
	        return await AddAttachmentToInvoice(invoiceNumber, memoryStream, fileName);
	    }
        public async Task<string> AddAttachmentToInvoice(string invoiceNumber, Stream stream, string fileName)
	    {
            if(stream == default(Stream))
                throw new ArgumentNullException(nameof(stream), "Stream is missing");
            if(string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(Path.GetExtension(fileName)))
                throw new ArgumentNullException(nameof(fileName), "File name must be provided and have an extention");
	        return await VismaNetApiHelper.AddAttachmentToInvoice(Authorization, invoiceNumber, stream, fileName);
	    }

        public async Task<Stream> PrintInvoice(CustomerInvoice invoice)
        {
            return await VismaNetApiHelper.InvoicePrint(invoice.GetIdentificator(), Authorization);
        }

	    public async Task<bool> Delete(string invoiceNumber)
{'fraction_non_alphanumeric': 0.09160178896803048, 'fraction_numerical': 0.00033129037601457677, 'mean_word_length': 2.951570680628272, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5988745', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1553, 'n_words': 352}