encode<V> static method

V encode<V>(
  1. Product instance,
  2. Encoder<V> encoder
)
override

Implementation

static V encode<V>(
  Product instance,
  Encoder<V> encoder,
) {
  final container = encoder.container<String>();
  container.encodeBool(
    'active',
    instance.active,
  );
  container.encodeDateTime(
    'created',
    instance.created,
  );
  if (instance.defaultPrice != null) {
    PriceOrId.encode(
      instance.defaultPrice!,
      container.nestedSingleValueContainer('default_price').encoder,
    );
  }
  if (instance.description != null) {
    container.encodeString(
      'description',
      instance.description!,
    );
  }
  container.encodeList(
    'features',
    (container) =>
        instance.features.forEach((el) => ProductMarketingFeature.encode(
              el,
              container.nestedSingleValueContainer().encoder,
            )),
  );
  container.encodeString(
    'id',
    instance.id,
  );
  container.encodeList(
    'images',
    (container) =>
        instance.images.forEach((el) => container.encodeString(el)),
  );
  container.encodeBool(
    'livemode',
    instance.livemode,
  );
  container.encodeMap(
    'metadata',
    (container) => instance.metadata.forEach((
      key,
      value,
    ) =>
        container.encodeString(
          key,
          value,
        )),
  );
  container.encodeString(
    'name',
    instance.name,
  );
  container.encodeString(
    'object',
    'product',
  );
  if (instance.packageDimensions != null) {
    PackageDimensions.encode(
      instance.packageDimensions!,
      container.nestedSingleValueContainer('package_dimensions').encoder,
    );
  }
  if (instance.shippable != null) {
    container.encodeBool(
      'shippable',
      instance.shippable!,
    );
  }
  if (instance.statementDescriptor != null) {
    container.encodeString(
      'statement_descriptor',
      instance.statementDescriptor!,
    );
  }
  if (instance.taxCode != null) {
    TaxCodeOrId.encode(
      instance.taxCode!,
      container.nestedSingleValueContainer('tax_code').encoder,
    );
  }
  container.encodeString(
    'type',
    instance.type,
  );
  if (instance.unitLabel != null) {
    container.encodeString(
      'unit_label',
      instance.unitLabel!,
    );
  }
  container.encodeDateTime(
    'updated',
    instance.updated,
  );
  if (instance.url != null) {
    container.encodeString(
      'url',
      instance.url!,
    );
  }
  return container.value;
}