using Dapper;
using Lada.Framework.Data.Domains.Cms;
using Lada.Framework.Data.Repositories;
using ladaexpress.vn.Infrastructures.DTO.Models.Home;
using ladaexpress.vn.Infrastructures.DTO.Models.Post.Index.Childs;
using System.Data;

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


    }

    public class HomeService : IHomeService
    {
        private readonly IRepository<Post> _postRepository;
        private readonly IDbConnection _dbConnection;

        public HomeService(IRepository<Post> postRepository, IRepository<UrlRecord> urlRecordRepository,
            IRepository<Category> categoryRepository, IDbConnection dbConnection)
        {
            _postRepository = postRepository;
            _dbConnection = dbConnection;
        }


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

            return model;
        }


    }
}
