using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using Dapper;
namespace XYY.Service.Standard.KnowledgeBase.Data
{
    public interface IKnowledgeBaseRepository : IBaseRepository<Model.KnowledgeBase>
    {
        Task<List<string>> GetDicts();

        Task<List<Model.KnowledgeBase>> GetFiles(string dictName);

        Task UpdateFile(Model.KnowledgeBase @base);
    }

    public class KnowledgeBaseRepository : BaseRepository<Model.KnowledgeBase>, IKnowledgeBaseRepository
    {
        public KnowledgeBaseRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }

        public async Task<List<string>> GetDicts()
        {
            return new List<string>
            {
                "仓库",
                "销售",
                "客服",
                "空运",
                "总经办",
                "IT",
                "财务",
                "人事行政"
            };
        }

        public async Task<List<Model.KnowledgeBase>> GetFiles(string dictName)
        {
            return (await QueryAsync(x => x.DictName == dictName)).ToList();
        }

        public async Task UpdateFile(Model.KnowledgeBase @base)
        {
            if (@base.Id > 0)
            {
                await UpdateAsync(@base);
            }
            else
            {
                await InsertAsync(@base);
            }
        }
    }





}
