<commit_before>﻿using SQLite.Net;
using SQLite.Net.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using SQLite.Net.Async;
using System.Threading.Tasks;
using BuenaHealth.Mobile.Models;

namespace BuenaHealth.Mobile
{
    public class UserRepository
    {
        private SQLiteAsyncConnection dbConn;
        
        public string StatusMessage { get; set; }

        public UserRepository(ISQLitePlatform sqlitePlatform, string dbPath)
        {
            //initialize a new SQLiteConnection 
            if (dbConn == null)
            {
                var connectionFunc = new Func<SQLiteConnectionWithLock>(() =>
                    new SQLiteConnectionWithLock
                        (
                            sqlitePlatform,
                            new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: false)
                        )
                );

                dbConn = new SQLiteAsyncConnection(connectionFunc);
                dbConn.CreateTableAsync<User>();
            }
        }

        public async Task AddNewUserAsync(User user)
        {
            int result = 0;
            try
            {
                //basic validation to ensure a name was entered
                if (string.IsNullOrEmpty(user.UserName))
                    throw new Exception("Valid FirstName required");

                //insert a new person into the Person table
                result = await dbConn.InsertAsync(new User
                {
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    UserName = user.UserName
                });
                StatusMessage = string.Format("{0} record(s) added [UserName: {1})", result, user.UserName);
            }
            catch (Exception ex)
            {
                StatusMessage = string.Format("Failed to add {0}. Error: {1}", user.UserName, ex.Message);
            }

        }

        public async Task<List<User>> GetAllUsersAsync()
        {
            //return a list of people saved to the Person table in the database<commit_msg>Fixing Typo in Error Message<commit_after>﻿using SQLite.Net;
using SQLite.Net.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using SQLite.Net.Async;
using System.Threading.Tasks;
using BuenaHealth.Mobile.Models;

namespace BuenaHealth.Mobile
{
    public class UserRepository
    {
        private SQLiteAsyncConnection dbConn;
        
        public string StatusMessage { get; set; }

        public UserRepository(ISQLitePlatform sqlitePlatform, string dbPath)
        {
            //initialize a new SQLiteConnection 
            if (dbConn == null)
            {
                var connectionFunc = new Func<SQLiteConnectionWithLock>(() =>
                    new SQLiteConnectionWithLock
                        (
                            sqlitePlatform,
                            new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: false)
                        )
                );

                dbConn = new SQLiteAsyncConnection(connectionFunc);
                dbConn.CreateTableAsync<User>();
            }
        }

        public async Task AddNewUserAsync(User user)
        {
            int result = 0;
            try
            {
                //basic validation to ensure a name was entered
                if (string.IsNullOrEmpty(user.UserName))
                    throw new Exception("Valid UserName required");

                //insert a new person into the Person table
                result = await dbConn.InsertAsync(new User
                {
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    UserName = user.UserName
                });
                StatusMessage = string.Format("{0} record(s) added [UserName: {1})", result, user.UserName);
            }
            catch (Exception ex)
            {
                StatusMessage = string.Format("Failed to add {0}. Error: {1}", user.UserName, ex.Message);
            }

        }

        public async Task<List<User>> GetAllUsersAsync()
        {
            //return a list of people saved to the Person table in the database
{'fraction_non_alphanumeric': 0.0748235294117647, 'fraction_numerical': 0.002352941176470588, 'mean_word_length': 1.5109273479031304, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6648027', 'n_tokens_mistral': 1035, 'n_tokens_neox': 984, 'n_words': 273}