using Dapper;
using ladaexpress.vn.Infrastructures.DTO.Models.Home;
using ladaexpress.vn.Infrastructures.DTO.Models.Post.Index.Childs;
using ladaexpress.vn.Infrastructures.DTO.Models.Service;
using System.Data;

namespace ladaexpress.vn.Infrastructures.Services
{
    public interface IServiceService
    {
        /// <summary>
        /// Home Model
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        Task<ServiceModel> PrepareServiceModel();


    }


    public class ServiceService : IServiceService
    {
        private readonly IDbConnection _dbConnection;

        public ServiceService(IDbConnection dbConnection)
        {
            _dbConnection = dbConnection;
        }

        public async Task<ServiceModel> PrepareServiceModel()
        {
            var model = new ServiceModel();
            try
            {
                model.LatestPosts = (await _dbConnection.QueryAsync<PostItem>("Home_GetLatestPosts", commandType: CommandType.StoredProcedure)).ToList();
            }
            catch (Exception)
            {
            }

            return model;
        }
    }
}
