using BBM.ChatGLM.ChatSession.Aggregates;
using BBM.ChatGLM.ChatSession.Repositorys;
using BBM.ChatGLM.Dtos;

namespace BBM.ChatGLM.ChatSession
{
    public class ChatSessionsManager : ChatGLMDomainService
    {
        private readonly IChatSessionFreeSqlRepository _chatSessionFreeSqlRepository;
        private readonly IChatSessionRepository _chatSessionRepository;
        public ChatSessionsManager(IChatSessionFreeSqlRepository chatSessionFreeSqlRepository, IChatSessionRepository chatSessionRepository)
        {
            _chatSessionFreeSqlRepository = chatSessionFreeSqlRepository;
            _chatSessionRepository = chatSessionRepository;
        }

        public async Task<ChatSessions> CreateAsync(ChatSessions input)
        {
            return await _chatSessionRepository.InsertAsync(input);
        }

        public async Task<ChatSessions> UpdateAsync(Guid id, string content)
        {
            var entity = await _chatSessionRepository.GetAsync(id);
            entity.Content = content;
            return await _chatSessionRepository.UpdateAsync(entity);
        }

        public async Task<List<ChatSessionDto>> PageAsync(string filter, int pageSize, int pageIndex)
        {
            return await _chatSessionFreeSqlRepository.PageAsync(filter, pageSize, pageIndex, CurrentTenant.Id);
        }

        public async Task<long> CountAsync(string filter)
        {
            return await _chatSessionFreeSqlRepository.CountAsync(filter, CurrentTenant.Id);
        }
    }
}
