using BBM.ChatGLM.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Guids;

namespace BBM.ChatGLM.PromptWord
{
    [Authorize]
    public class PromptWordsAppService : ChatGLMAppService, IPromptWordsAppService
    {
        private readonly PromptWordsManager _promptWordsManager;
        private readonly IGuidGenerator _guidGenerator;
        public PromptWordsAppService(PromptWordsManager promptWordsManager, IGuidGenerator guidGenerator)
        {
            _promptWordsManager = promptWordsManager;
            _guidGenerator = guidGenerator;
        }

        [Authorize(ChatGLMPermissions.PromptWordManagement.Create)]
        public async Task<PromptWordDto> CreateAsync(PromptWordCreateInput input)
        {
            var data = await _promptWordsManager.CreateAsync(new PromptWords(_guidGenerator.Create(), input.Type, input.Content, CurrentTenant.Id));
            return ObjectMapper.Map<PromptWords, PromptWordDto>(data);
        }

        [Authorize(ChatGLMPermissions.PromptWordManagement.Update)]
        public async Task<PromptWordDto> UpdateAsync(PromptWordUpdateInput input)
        {
            var data = await _promptWordsManager.UpdateAsync(new PromptWords(input.Id, input.Type, input.Content));
            return ObjectMapper.Map<PromptWords, PromptWordDto>(data);
        }

        [Authorize(ChatGLMPermissions.PromptWordManagement.Delete)]
        public async Task<int> DeleteAsync(GuidIdInput input)
        {
            return await _promptWordsManager.DeleteAsync(input.Id);
        }

        [Authorize(ChatGLMPermissions.PromptWordManagement.Query)]
        public async Task<PagedResultDto<PromptWordDto>> PageAsync(PromptWordPageInput input)
        {
            var result = new PagedResultDto<PromptWordDto>
            {
                TotalCount = await _promptWordsManager.CountAsync(input.Filter, input.Type)
            };

            var data = await _promptWordsManager.PageAsync(input.Filter, input.Type, input.PageSize, input.PageIndex);
            result.Items = ObjectMapper.Map<List<PromptWords>, List<PromptWordDto>>(data);
            return result;
        }
    }
}
