using AutoMapper; using Common.Dtos; using Hushian.Application.Contracts.Persistence; using Hushian.Application.Models; using Hushian.Domain.Entites; using Microsoft.EntityFrameworkCore; using System.Linq; namespace Hushian.Application.Services { public class AIService { private readonly IGenericRepository _aiaRepository; private readonly IMapper _mapper; public AIService(IGenericRepository aiaRepository, IMapper mapper) { _aiaRepository = aiaRepository; _mapper = mapper; } public async Task> NewRequest (aiNewResponseDto dto) { ResponseBase response = new(); try { string responeai="همین جوری"; bool sucessresponseai = false; var entity = new AIA { CompanyID = dto.companyId, UserID = dto.userId, Request = dto.requestText, Response = responeai, Cdatetime = DateTime.Now }; var added = await _aiaRepository.ADD(entity); if(sucessresponseai) response.Value = new() { dateTime=added.Cdatetime,responseText=added.Response,requestText=added.Request}; response.Success = sucessresponseai; } catch (Exception) { response.Errors.Add("خطا در ذخیره سازی"); } return response; } public async Task> GetCurrent(int companyId, int userId) { return await _aiaRepository .Get() .Where(w => w.CompanyID == companyId && w.UserID == userId && w.Cdatetime.AddHours(3) >= DateTime.Now) .OrderBy(o => o.ID) .Select(s=>new aiResponseDto() { responseText = s.Response, requestText = s.Request,dateTime=s.Cdatetime}) .ToListAsync(); } //public async Task DeleteEntry(int id, int companyId) //{ // var entity = await _aiaRepository.Get().FirstOrDefaultAsync(f => f.ID == id && f.CompanyID == companyId); // if (entity == null) return false; // return await _aiaRepository.DELETE(entity); //} } }