using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Threading;

using BeWo.Core;
using BeWo.ViewModel;
using BeWo.ServiceProxy;

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

using Microsoft.Win32;

namespace BeWo.View
{
    public partial class ChatServiceCustomer
    {
        
      

        private CustomerVM _ViewModel;

        long? customerOid;

        public ChatServiceCustomer(TableID pObjectTid, long? oid)
        {
            InitializeComponent();

            customerOid = oid;


            LaodInfostoView();
        }


        public CustomerVM PublicViewModel { get { return _ViewModel; } }




        public override bool IsDirty
        {
            get
            {
                return ViewModel != null && ViewModel.IsDirty;
            }
        }

       private CustomerVM ViewModel
        {
            get { return _ViewModel; }

            set
            {
                DataContext = value;
                _ViewModel = value;
            }
        }




        private void GenerateCodeClick(object sender, RoutedEventArgs e)
        {

            var result = ServiceFacade.DoOperationsServiceSync(s => s.CreateNewCustomerAPPCodeDC(customerOid.Value));

            GeneratetTexfield.Text = result.CustomerCode;

        }

        //################### Bugs Vorhanden / statt new Create ein Update genügt ###########################################
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {

            ServiceFacade.DoOperationsServiceSync(s => s.CreateNewIsChatActiveCustomerAPPCodeDC(customerOid.Value, 1));
            // result.IsChatAktive = 1;

             //ServiceFacade.DoOperationsServiceSync(s => s.CreateNewEmployeeAPPCodeDC(2));
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            //hehe nö nicht funkt
            ServiceFacade.DoOperationsServiceSync(s => s.CreateNewIsChatActiveCustomerAPPCodeDC(customerOid.Value, 0));
            // var result = ServiceFacade.DoOperationsServiceSync(s => s.CreateNewCustomerAPPCodeDC(ViewModel.DataContract.CustomerOid.Value));
            // result.IsChatAktive = 0;
        }


        private void LaodInfostoView()
        {
            
            var getCustomerAppCode = ServiceFacade.DoCustomerServiceSync(s => s.GetAllCustomerAppCodes(customerOid.Value));

            int x = getCustomerAppCode[getCustomerAppCode.Count - 1].IsChatAktive;


            if (x == 0)
                ChatAktive.SetCurrentValue(CheckBox.IsCheckedProperty, false);
            else
                ChatAktive.SetCurrentValue(CheckBox.IsCheckedProperty, true);


            GeneratetTexfield.Text = getCustomerAppCode[getCustomerAppCode.Count - 1].CustomerCode;
         
        }




    }
}