using System.Threading.Tasks;
using MDL.Models;
using DAL.Interfaces;
using DB.Database;
using SqlSugar;

namespace DAL.Repositories
{
    public class TagRepository : ITagRepository
    {
        private readonly ISqlSugarProvider _provider;

        public TagRepository(ISqlSugarProvider provider)
        {
            _provider = provider;
        }

        public async Task SaveResultAsync(string id, string result)
        {
            var db = _provider.GetClient();
            var entity = new TagResultEntity
            {
                RequestId = id,
                Result = result,
                CreatedAt = DateTime.UtcNow
            };
            // ensure table exists (simple auto-creation)
            db.CodeFirst.InitTables(typeof(TagResultEntity));
            await db.Insertable(entity).ExecuteCommandAsync();
        }
    }
}
