using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using Datory;
using GxPress.Common.AppOptions;
using GxPress.Common.Tools;
using GxPress.Entity.ArticleLabel;
using GxPress.Repository.Interface.ArticleLabel;
using Microsoft.Extensions.Options;
using SqlKata;

namespace GxPress.Repository.Implement.ArticleLabel
{

    public class ArticleInnerLabelRepository : IArticleInnerLabelRepository
    {
        private readonly Repository<Entity.ArticleLabel.ArticleInnerLabel> _repository;
        private readonly IMapper _mapper;

        public ArticleInnerLabelRepository(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.ArticleLabel.ArticleInnerLabel>(database);
            _mapper = mapper;
        }

        public IDatabase Database => _repository.Database;
        public string TableName => _repository.TableName;
        public List<TableColumn> TableColumns => _repository.TableColumns;

        public async Task<bool> DeleteAsync(Query query)
        {
            return await _repository.DeleteAsync(query) > 0;
        }

        public async Task<IEnumerable<ArticleInnerLabel>> GetAllAsync(Query query)
        {
            return await _repository.GetAllAsync(query);
        }

        public async Task<ArticleInnerLabel> GetAsync(int id)
        {
            return await _repository.GetAsync(id);
        }

        public async Task<int> InsertAsync(ArticleInnerLabel articleInnerLabel)
        {
            return await _repository.InsertAsync(articleInnerLabel);
        }

        public async Task<bool> UpdateAsync(ArticleInnerLabel articleInnerLabel)
        {
            return await _repository.UpdateAsync(articleInnerLabel);
        }

        public async Task<bool> UpdateAsync(Query query)
        {
            return await _repository.UpdateAsync(query) > 0;
        }
    }
}