using LinqToDB;
using LinqToDB.Configuration;
using LinqToDB.Data;
using zotanpw.Backend.database.Tables;

namespace zotanpw.Backend.database;

public class Database {
	private class ConnectionStringSettings : IConnectionStringSettings {
		public string ConnectionString { get; set; } = null!;
		public string Name             { get; set; } = null!;
		public string ProviderName     { get; set; } = null!;
		public bool   IsGlobal         => false;
	}

	public class Settings : ILinqToDBSettings {
		public IEnumerable<IDataProviderSettings> DataProviders => Enumerable.Empty<IDataProviderSettings>();

		public string DefaultConfiguration => "SQLite";
		public string DefaultDataProvider  => "SQLite";

		public IEnumerable<IConnectionStringSettings> ConnectionStrings {
			get { yield return new ConnectionStringSettings { Name = "db", ProviderName = "SQLite", ConnectionString = @"Data Source=database.db;" }; }
		}
	}

	public class DbConn : DataConnection {
		public DbConn() : base("db") { }
		public ITable<DbInfo>               DbInfo          => this.GetTable<DbInfo>();
		public ITable<TravelynxInfo>        TravelynxInfo   => this.GetTable<TravelynxInfo>();
		public ITable<AlbumHistoryEntry>    AlbumHistory    => this.GetTable<AlbumHistoryEntry>();
		public ITable<PlaylistHistoryEntry> PlaylistHistory => this.GetTable<PlaylistHistoryEntry>();
	}
}