using System;
using EspaceClient.BackOffice.Silverlight.Business.Depots;
using EspaceClient.BackOffice.Silverlight.Business.Interfaces;
using EspaceClient.BackOffice.Silverlight.ViewModels.Common.Modularity;
using EspaceClient.BackOffice.Silverlight.ViewModels.Helper.Administration.Profils;
using nRoute.Components.Composition;
using OGDC.Silverlight.Toolkit.Services.Services;

namespace EspaceClient.BackOffice.Silverlight.ViewModels.Administration.Profils.Tabs
{
    public partial class DetailsViewModel : TabBase
    {
        private readonly IDepotProfil _profilDepot;
        private readonly IDepotTraductionOM _traductionOMDepot;

        private ProfilsEntityViewModel _entity;

        public ProfilsEntityViewModel Entity
        {
            get
            {
                return _entity;
            }

            set
            {
                if (_entity != value)
                {
                    _entity = value;
                    NotifyPropertyChanged(() => Entity);
                }
            }
        }

        [ResolveConstructor]
        public DetailsViewModel(IApplicationContext applicationContext, IMessenging messengingService, IDepotProfil profilDepot, IDepotTraductionOM traductionOMDepot)
            : base(applicationContext, messengingService)
        {
            _profilDepot = profilDepot;
            _traductionOMDepot = traductionOMDepot;
        }

        public override void OnRefreshTab<EntityType>(long id, Action<EntityType> callback)
        {
            ProfilsHelper.LoadContext(
                id,
                _messengingService,
                _profilDepot,
                _traductionOMDepot,
                entity =>
                {
                    callback(entity as EntityType);
                });
        }

        protected override void OnRefreshTabCompleted(Action callback)
        {
            callback();
        }
    }
}
