﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Castle.Core.Logging;
using SOURCE.Infrastructure.Services.Depots;
using SOURCE.Infrastructure.Services.Encryption;
using SOURCE.Infrastructure.Services.Parameters;
using SOURCE.Infrastructure.Services.Translation;
using SOURCE.Web.Controllers.Modularity;
using SOURCE.Web.Controllers.Helpers;
using SOURCE.Infrastructure.Constant;
using SOURCE.Web.Controllers.Filters;
using System.Net;
using SOURCE.Web.Controllers.ActionResults;
using SOURCE.Infrastructure.Extensions;
using SOURCE.Domaine.Composite;
using SOURCE.Domaine.Results;
using SOURCE.Web.ViewModels.ModelBuilders.Common;
using System.Text;
using SOURCE.Domaine.Exceptions;
using System;
using SOURCE.Web.ViewModels.ModelBuilders.Intervenant.Intervenant;
using SOURCE.Infrastructure.Attributes.Modularity;
using SOURCE.Web.ViewModels.Pages.Common;

namespace SOURCE.Web.Controllers.Administration
{
    public class IntervenantControllerBase : ModularController
    {
        public IntervenantControllerBase(
            ILogger logger,
            ICryptography encryption,
            IDepotFactory depotFactory,
            ITranslator translatorService,
            IParameter parameterService,
            ICommonModelBuilder commonModelBuilder)
            : base(logger, encryption, depotFactory, translatorService, parameterService, commonModelBuilder)
        {

        }

        public override void ProcessNavBar(PageViewModel page, string codePage)
        {
            page.NavBar = _commonModelBuilder.BuildNavBarStaticViewModel(Context, _translatorService.TranslateToString("FICHE_INTERVENANT"));
        }

        public override void ProcessPageTitle(PageViewModel page, string codePage, long? idFonctionnel)
        {
            page.Title = string.Empty;

            if (!idFonctionnel.HasValue)
            {
                return;
            }

            var intervenant = _depotFactory.PersonneDepot.GetById(idFonctionnel.Value);
            if (intervenant == null)
            {
                return;
            }

            page.Title = string.Format("{0}, {1}", intervenant.Nom, intervenant.Prenom).Trim();
        }
    }
}
