import type { DataDomain, DataDomainSchema } from './DataDomain.js'
import type { ForeignDomainDependency } from './types.js'

export type DomainDependency = DataDomain | DataDomainSchema

export interface DependentModelSchema {
  /**
   * A list of foreign domain dependencies.
   */
  dependencyList?: ForeignDomainDependency[]
}

/**
 * A base model that has dependencies on foreign data domains.
 */
export class DependentModel extends EventTarget {
  /**
   * A map of foreign data domains.
   * Key: The unique identifier of the foreign domain.
   * Value: The foreign DataDomain instance.
   */
  dependencies: Map<string, DataDomain> = new Map<string, DataDomain>()

  /**
   * The list of foreign domain dependencies.
   */
  dependencyList: ForeignDomainDependency[] = []

  constructor(items: ForeignDomainDependency[] = [], instances: DataDomain[] = []) {
    super()
    this.dependencyList = [...items]
    for (const dep of instances) {
      this.dependencies.set(dep.key, dep)
    }
  }
}
