﻿using System;
using System.IO;

using Xamarin.Forms;

using TeenTixMobileNEW;
using TeenTix.Common.DB;

[assembly: Dependency (typeof (SQLite_iOS))]

namespace TeenTixMobileNEW
{
	public class SQLite_iOS : ISQLite
	{
		private string path;

		public SQLite_iOS ()
		{
		}

		public SQLite.SQLiteConnection GetConnection() {
			var sqlFilename = "TeenTixDb.db3";
			string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
			string libraryPath = Path.Combine (documentsPath, "..", "Library", "Caches");
			path = Path.Combine (libraryPath, sqlFilename);

			Console.WriteLine ("SQLite file path: {0}", path);
			if (!File.Exists (path)) {
				// TODO: do we need to do anything here? (thomasvandoren, 2016-04-25)
			}

			var conn = new SQLite.SQLiteConnection (path);
			return conn;
		}

		public void ClearDatabase() {
			Console.WriteLine ("Deleting database file: {0}", path);
			File.Delete (path);
		}
	}
}

