using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

using C4IT.FASD.Base;
using C4IT.FASD.Cockpit.Communication;
using C4IT.Logging;
using C4IT.MultiLanguage;

using FasdDesktopUi.Basics.Models;

using FasdDesktopUi.Basics.UserControls;
using FasdDesktopUi.Pages.DetailsPage;
using FasdDesktopUi.Pages.DetailsPage.UserControls;

using static C4IT.Logging.cLogManager;

namespace FasdDesktopUi.Basics.UiActions
{
    public class cChangeHealthCardAction : cUiActionBase
    {
        public cF4sdApiSearchResultRelation ResultRelation { get; private set; } = null;

        public cChangeHealthCardAction(cF4sdApiSearchResultRelation resultRelation)
        {
            ResultRelation = resultRelation;
        }

        public override async Task<bool> RunUiActionAsync(object sender, UIElement UiLocation, bool isDetailedLayout, cSupportCaseDataProvider dataProvider)
        {

            var CM = MethodBase.GetCurrentMethod();
            LogMethodBegin(CM);
            try
            {
                if (dataProvider == null)
                    return false;
                if (ResultRelation == null)
                    return false;
                if (!(UiLocation is DetailsPageView detailsPage))
                    return false;

                Mouse.OverrideCursor = Cursors.Wait;

                detailsPage.NavigationHeadingUc.ResetSelectors();

                await dataProvider.ExchangeCaseIdentitiesAsync(ResultRelation);

                return true;
            }
            catch (Exception E)
            {
                LogException(E);
            }
            finally
            {
                Mouse.OverrideCursor = null;
                LogMethodEnd(CM);
            }

            return false;
        }

    }
}
