using GxPress.Service.Interface.FileLibrary;
using GxPress.Repository.Interface;
using System.Threading.Tasks;
using GxPress.Service.Interface.Collection;
using GxPress.Request.App.Collection;

namespace GxPress.Service.Implement.FileLibrary
{
    public class FileLibraryService : IFileLibraryService
    {
        private readonly IFileLibraryRepository fileLibraryRepository;
        private readonly ICollectionService collectionService;
        public FileLibraryService(IFileLibraryRepository fileLibraryRepository, ICollectionService collectionService)
        {
            this.fileLibraryRepository = fileLibraryRepository;
            this.collectionService = collectionService;
        }
        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<int> InsertAsync(Entity.FileLibrary request)
        {

            var fileLibraryId = await fileLibraryRepository.InsertAsync(request);
            if (request.UserId > 0)
            {
                var collectionInRequest = new CollectionInRequest();
                //记录收藏
                collectionInRequest.CollectionType = 300;
                collectionInRequest.CollectionDataId = fileLibraryId;
                collectionInRequest.UserId = request.UserId;
                await collectionService.Insert(collectionInRequest);
            }
            return fileLibraryId;
        }
    }
}