# Migrates role purchase licenses from UC Roles module.
# This is incomplete and is specificaly created for materio.
id: d7_uc_roles_license
label: License from D7 Ubercart Roles.
migration_group: d7_materio
migration_tags:
  - Drupal 7
  - Ubercart
  - Materio

source:
  plugin: d7_uc_license_role

destination:
  plugin: entity:commerce_license
  destination_module: commerce_license

process:
  type:
    # Migrate into the role license type.
    plugin: default_value
    default_value: role
  uid:
    -
      plugin: skip_on_empty
      method: row
      source: uid
    -
      plugin: migration_lookup
      migration: d7_users
      # source: uid
      no_stub: true
  # state:
  #   plugin: default_value
  #   default_value: active
  state: state
  created: created
  granted: created
  renewed: renewed
  changed: renewed
  license_role:
    plugin: static_map
    source: rid
    map:
      6: adherent
      10: student

  expiration_type:
    # This assumes Commerce Recurring is used with licenses.
    plugin: default_value
    default_value:
      target_plugin_id: rolling_interval
      target_plugin_configuration:
        interval:
          interval: 1
          period: year


      # array (
      #   'interval' => array (
      #     'interval' => '6',
      #     'period' => 'month',
      #   ),
      # )

  # expires:
  #   # This assumes Commerce Recurring is used with licenses.
  #   plugin: default_value
  #   default_value: 0
  expires: expiration

  # product_variation:
  #   plugin: migration_lookup
  #   migration: # your product variation migration
  #   source: nid
  product_variation: product_variation_id
    # plugin: static_map
    # source: rid
    # map:
    #   6: 2 # web annual
    #   10: 7 # web annual

migration_dependencies:
  required:
    - d7_users
  optional: {}

dependencies:
  enforced:
    module:
      - commerce_product
      - commerce_license
