using Disco.Data.Repository;
using Disco.Models.BI.Config;
using Disco.Models.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Disco.Services.Plugins.Features.InsuranceProvider
{
[PluginFeatureCategory(DisplayName = "Insurance Providers")]
public abstract class InsuranceProviderFeature : PluginFeature
{
///
/// The insurer identifier. Used to link this provider to any . This identifier is used to automatically set the Insurer when a job is submitted using this plugin.
///
public abstract string ProviderId { get; }
#region Job Submission
///
/// Called when a user selects this plugin to submit the insurance claim and allows a plugin to inject a View to collect additional information.
///
/// A Tuple consisting of the Razor View type and a View Model
public virtual Tuple SubmitJobBegin(DiscoDataContext database, Controller controller, Job job, OrganisationAddress address, User techUser)
{
return null;
}
///
/// Called after the RepairDescription is completed and allows the plugin to parse any data collected from SubmitJobBegin.
///
/// A Dictionary of key/value items which are persisted throughout the submission and passed into the final SubmitJob method.
public virtual Dictionary SubmitJobParseProperties(DiscoDataContext database, FormCollection form, Controller controller, Job job, OrganisationAddress address, User techUser)
{
return null;
}
///
/// Plugins are required to disclose any information that will be transmitted to any external party. This method is expected to return a clear list all data which will be transmitted.
///
/// A Dictionary of key/value items which contain all information which will be disclosed to the plugin provider.
public abstract Dictionary SubmitJobDiscloseInfo(DiscoDataContext database, Job job, OrganisationAddress address, User techUser, Dictionary providerProperties);
///
/// Called when the plugin should submit the job to the external party.
///
/// A reference number/identifier from the external party which is stored in
public abstract string SubmitJob(DiscoDataContext database, Job job, OrganisationAddress address, User techUser, List attachments, Dictionary providerProperties);
#endregion
#region Job Details
///
/// when additional Job Details are supported by the external party. When , JobDetailsViewModel must be implemented.
///
public abstract bool JobDetailsSupported { get; }
///
/// Called when a job's insurance information is shown. Allows a plugin to inject a View to display additional information.
///
/// A Tuple consisting of the Razor View type and a View Model
public virtual Tuple JobDetails(DiscoDataContext database, Controller controller, Job job)
{
return null;
}
#endregion
public static PluginFeatureManifest FindPluginFeature(string pluginIdOrInsuranceProviderId)
{
var defs = Plugins.GetPluginFeatures(typeof(InsuranceProviderFeature));
var def = defs.FirstOrDefault(d => d.PluginManifest.Id.Equals(pluginIdOrInsuranceProviderId, StringComparison.OrdinalIgnoreCase));
if (def != null)
return def;
else
foreach (var d in defs)
{
using (var providerInstance = d.CreateInstance())
{
if (providerInstance.ProviderId != null && providerInstance.ProviderId.Equals(pluginIdOrInsuranceProviderId, StringComparison.OrdinalIgnoreCase))
{
return d;
}
}
}
return null;
}
}
}