﻿using Castle.Core.Logging;
using SOURCE.Domaine;
using SOURCE.Domaine.Composite;
using SOURCE.Domaine.Results;
using SOURCE.Infrastructure.Constant;
using SOURCE.Infrastructure.Services.Depots;
using SOURCE.Infrastructure.Services.Caching;
using System;
using System.Linq;
using System.Collections.Generic;
using AutoMapper;
using SOURCE.EspaceCandidature.Web.ViewModels.Pages.Public.ConfirmationPreReservation;
using SOURCE.EspaceCandidature.Web.ViewModels.Pages.Planning;

namespace SOURCE.EspaceCandidature.Web.ViewModels.ModelBuilders.Public.ConfirmationPreReservation
{
    public class ConfirmationPreReservationModelBuilder : ModelBuilderBase, IConfirmationPreReservationModelBuilder
    {
        public ConfirmationPreReservationModelBuilder(ILogger logger, IDepotFactory depotFactory, ICaching cachingService)
            : base(logger, depotFactory, cachingService)
        { }

        public PreReservationViewModel BuildPreReservationViewModel(Context context, string token, long demandeID, long personneID, bool acceptee)
        {
            var preReservationDetails = _depotFactory.DemandeDepot.GetPreReservationDetails(demandeID, personneID);
            var preReservationEvents =  _depotFactory.DemandeDepot.GetDemandePreReservations(demandeID, personneID);

            return new PreReservationViewModel(context, _cachingService)
            {
                PreReservationDetails = preReservationDetails,
                Token = token,
                ConfirmationMessage = acceptee ? _cachingService.Translate("CONFIRMATION_PRERESERVATION_MESSAGE_ACCEPTEE") : _cachingService.Translate("CONFIRMATION_PRERESERVATION_MESSAGE_REFUS"),
                Acceptee= acceptee,
                PreReservationEvents = Mapper.Map<IEnumerable<PlanningResult>, IEnumerable<PlanningEventViewModel>>(preReservationEvents)
            };
        }
    }
}
