import { ITableRow } from "./ITableRow";

export abstract class TableBase<TRow extends ITableRow> extends Array<TRow> {
	constructor() {
		super();
		Object.setPrototypeOf(this, new.target.prototype);
	}

	/** 欄位數量 */
	public get Count(): number {
		return this.length;
	}

	/** 取得全部鍵值 */
	public get Keys(): string[] {
		return Object.keys(this);
	}

	/** 取得全部欄位值 */
	public get Rows(): Array<TRow> {
		return Object["values"](this);
	}

	// public get Rows(): Array<TRow> { return this; }

	/** 是否包含該Id值的欄位 */
	public ContainsRow(id: number): boolean {
		return id in this;
	}
}