fromDomain static method

ComponentModel fromDomain(
  1. ComponentTemplate template
)

Implementation

static ComponentModel fromDomain(ComponentTemplate template) {
  final model = ComponentModel()
    ..componentId = template.id
    ..name = template.name
    ..manufacturer = template.manufacturer
    ..series = template.series
    ..isFavorite = template.isFavorite
    ..createdAt = DateTime.now();

  template.when(
    protection: (id, name, manufacturer, series, isFavorite, ratedCurrent,
        curveType, breakingCapacity, poles, deviceType, sensitivity, price) {
      model
        ..type = ComponentType.protection
        ..ratedCurrent = ratedCurrent
        ..curveType = curveType
        ..breakingCapacity = breakingCapacity
        ..poles = poles
        ..protectionDeviceType = deviceType
        ..sensitivity = sensitivity
        ..price = price;
    },
    cable: (id, name, manufacturer, series, isFavorite, section, material,
        insulationType, maxOperatingTemp, installationMethod, price) {
      model
        ..type = ComponentType.cable
        ..section = section
        ..cableMaterial = material
        ..insulationType = insulationType
        ..maxOperatingTemp = maxOperatingTemp
        ..installationMethod = installationMethod
        ..price = price;
    },
    source: (id, name, manufacturer, series, isFavorite, voltage,
        maxShortCircuitCurrent, ratedPower, sourceType, price) {
      model
        ..type = ComponentType.source
        ..voltage = voltage
        ..maxShortCircuitCurrent = maxShortCircuitCurrent
        ..ratedPower = ratedPower
        ..sourceType = sourceType
        ..price = price;
    },
  );

  return model;
}