using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Datory;
using GxPress.Common.AppOptions;
using GxPress.Common.Tools;
using GxPress.Repository.Interface.AppReport;
using Microsoft.Extensions.Options;

namespace GxPress.Repository.Implement.AppReport
{
   public class AppReportRepository: IAppReportRepository
    {
        private readonly Repository<Entity.AppReport> _repository;
        private readonly IMapper _mapper;

        public AppReportRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
        {
            var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
            var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
            _repository = new Repository<Entity.AppReport>(database);
            _mapper = mapper;
        }

        public IDatabase Database => _repository.Database;
        public string TableName => _repository.TableName;
        public List<TableColumn> TableColumns => _repository.TableColumns;
        public async Task<int> InsertAsync(Entity.AppReport appReport)
        {
            return await _repository.InsertAsync(appReport);
        }

        public async Task<bool> UpdateAsync(Entity.AppReport appReport)
        {
            return await _repository.UpdateAsync(appReport);
        }

        public async Task<IEnumerable<Entity.AppReport>> GetAppReportListAsync()
        {
            return await _repository.GetAllAsync();
        }

        public async Task<bool> DeleteAsyncTask(int id)
        {
            return await _repository.DeleteAsync(id);
        }

        public async Task<Entity.AppReport> GetAppReport(int reportType)
        {
            return await _repository.GetAsync(Q.Where(nameof(Entity.AppReport.ReportType), reportType));
        }
    }
}
