using System.Diagnostics; using Strata.SqlTools.SqlBreakdown.Interfaces.Core; namespace Strata.SqlTools.SqlBreakdown.Classes; #pragma warning disable S1694 // An abstract class should have both abstract and concrete methods public abstract class SelectSource : IVisitable { public abstract T Accept(IVisitor visitor); } [DebuggerDisplay("{TableName}")] public class TableSource : SelectSource { public string TableName { get; } public string? Schema { get; } public string? Alias { get; } public TableSource(string tableName) : this(tableName, null) { } #pragma warning disable S3427 // Method overloads with default parameter values should not overlap public TableSource(string tableName, string? schema = null, string? alias = null) { TableName = string.IsNullOrWhiteSpace(tableName) ? throw new ArgumentNullException(nameof(tableName)) : tableName; Schema = string.IsNullOrWhiteSpace(schema) ? null : schema; Alias = string.IsNullOrWhiteSpace(alias) ? null : alias; } #pragma warning restore S3427 public override T Accept(IVisitor visitor) { return visitor.VisitTableSource(this); } } public class RegisteredTableSource : TableSource { public int TableId { get; } public RegisteredTableSource(int tableId, string tableSchema, string tableName) : this(tableId, tableSchema, tableName, null) { } public RegisteredTableSource(int tableId, string tableSchema, string tableName, string? alias) : base(tableName, tableSchema, alias) { if (tableId <= 0) { throw new ArgumentException("tableId must be greater than 0", nameof(tableId)); } if (string.IsNullOrWhiteSpace(tableSchema)) { throw new ArgumentException("tableName cannot be null or whitespace", nameof(tableSchema)); } if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentException("tableName cannot be null or whitespace", nameof(tableName)); } TableId = tableId; } } #pragma warning restore S1694