---

- name: (Deprecation) Warn about mxisd variables that are not used anymore
  fail:
    msg: >
      The `{{ item }}` variable defined in your configuration is not used by this playbook anymore!
      You'll need to adapt to the new way of extending mxisd configuration.
      See the CHANGELOG and the `matrix_mxisd_configuration_extension_yaml` variable for more information and examples.
  when: "item in vars"
  with_items:
    - 'matrix_mxisd_ldap_enabled'
    - 'matrix_mxisd_ldap_connection_host'
    - 'matrix_mxisd_ldap_connection_tls'
    - 'matrix_mxisd_ldap_connection_port'
    - 'matrix_mxisd_ldap_connection_baseDn'
    - 'matrix_mxisd_ldap_connection_baseDns'
    - 'matrix_mxisd_ldap_connection_bindDn'
    - 'matrix_mxisd_ldap_connection_bindPassword'
    - 'matrix_mxisd_ldap_filter'
    - 'matrix_mxisd_ldap_attribute_uid_type'
    - 'matrix_mxisd_ldap_attribute_uid_value'
    - 'matrix_mxisd_ldap_connection_bindPassword'
    - 'matrix_mxisd_ldap_attribute_name'
    - 'matrix_mxisd_ldap_attribute_threepid_email'
    - 'matrix_mxisd_ldap_attribute_threepid_msisdn'
    - 'matrix_mxisd_ldap_identity_filter'
    - 'matrix_mxisd_ldap_identity_medium'
    - 'matrix_mxisd_ldap_auth_filter'
    - 'matrix_mxisd_ldap_directory_filter'
    - 'matrix_mxisd_template_config'

- name: Ensure mxisd configuration does not contain any dot-notation keys
  fail:
    msg: >
      Since version 1.3.0, mxisd will not accept property-style configuration keys.
      You have defined a key (`{{ item.key }}`) which contains a dot.
      Instead, use nesting. See: https://github.com/kamax-matrix/mxisd/wiki/Upgrade#v130
  when: "'.' in item.key"
  with_dict: "{{ matrix_mxisd_configuration }}"

- name: Fail if required mxisd settings not defined
  fail:
    msg: >
      You need to define a required configuration setting (`{{ item }}`) for using mxisd.
  when: "vars[item] == ''"
  with_items:
    - "matrix_mxisd_threepid_medium_email_connectors_smtp_host"


- name: (Deprecation) Catch and report renamed mxisd variables
  fail:
    msg: >-
      Your configuration contains a variable, which now has a different name.
      Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
  when: "item.old in vars"
  with_items:
    - {'old': 'matrix_mxisd_container_expose_port', 'new': '<superseded by matrix_mxisd_container_http_host_bind_port>'}