// This file was auto-generated by ML.NET Model Builder. 
using Microsoft.ML;
using Microsoft.ML.Data;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
namespace Recommendation
{
    public partial class MLModelRecommendation
    {
        /// <summary>
        /// model input class for MLModelRecommendation.
        /// </summary>
        #region model input class
        public class ModelInput
        {
            [ColumnName(@"RatingId")]
            public float RatingId { get; set; }

            [ColumnName(@"UserId")]
            public float UserId { get; set; }

            [ColumnName(@"PlaceIdOrigin")]
            public float PlaceIdOrigin { get; set; }

            [ColumnName(@"PlaceIdDestiny")]
            public float PlaceIdDestiny { get; set; }

            [ColumnName(@"Rating")]
            public float Rating { get; set; }

        }

        #endregion

        /// <summary>
        /// model output class for MLModelRecommendation.
        /// </summary>
        #region model output class
        public class ModelOutput
        {
            public float Score { get; set; }
        }
        #endregion

        private static string MLNetModelPath = Path.GetFullPath("MLModelRecommendation.zip");

        public static readonly Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(() => CreatePredictEngine(), true);

        /// <summary>
        /// Use this method to predict on <see cref="ModelInput"/>.
        /// </summary>
        /// <param name="input">model input.</param>
        /// <returns><seealso cref=" ModelOutput"/></returns>
        public static ModelOutput Predict(ModelInput input)
        {
            var predEngine = PredictEngine.Value;
            return predEngine.Predict(input);
        }

        private static PredictionEngine<ModelInput, ModelOutput> CreatePredictEngine()
        {
            var mlContext = new MLContext();
            ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);
            return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
        }
    }
}
