using System;
using System.Globalization;
using System.Windows.Data;

using BeWo.Core;
using BeWo.ViewModel;

using BS.Shared.Core;
using BS.Shared.DataContracts;

namespace BeWo.Converter
{
    public class SettlementDCPrintURLConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            String oidString = String.Empty;
            ReportTypes typ = ReportTypes.Settlement;
            var lVM = value as SettlementVM;

            if (lVM != null)
            {
                oidString = "dcid=" + lVM.DataContract.SettlementIvoiceOid.Value;
            }
            else
            {
                var sivm = value as ServiceInvoiceVM;

                if (sivm != null)
                {
                    oidString = "dcids=" + sivm.DataContract.ServiceInvoiceOid.Value;
                    typ = ReportTypes.ServiceInvoice;
                }
            }

            string url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?" + oidString + "&type=" + Utils.EnumName(typ);

            url = BeWoWpfUtils.GetHTMLEncodedURL(url);

            var lResult = new Uri(url);

            return lResult;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}