- name: Ensure user group for audio/video exists
  ansible.builtin.group:
    name: "{{ item }}"
    state: present
  loop: "{{ audio_groups }}"

- name: Put user in audio group
  ansible.builtin.user:
    name: "{{ user_name }}"
    groups: "{{ audio_groups }}"
    append: true

- name: Install pipewire
  community.general.xbps:
    name:
      - pipewire
    state: present
  tags: packages

- name: Install pipewire bluetooth
  community.general.xbps:
    name:
      - libspa-bluetooth
    state: present
  tags:
    - packages
    - bluetooth

- name: Set up wireplumber to auto start
  ansible.builtin.file:
    dest: "/etc/pipewire/pipewire.conf.d"
    state: directory

  # FIXME: Does not work automatically for some reason?
- name: Set up wireplumber to auto start
  ansible.builtin.file:
    force: "yes"
    src: "/usr/share/examples/wireplumber/10-wireplumber.conf"
    dest: "/etc/pipewire/pipewire.conf.d/10-wireplumber.conf"
    state: link

- name: Enable pipewire-pulse interface
  ansible.builtin.file:
    force: "yes"
    src: "/usr/share/examples/pipewire/20-pipewire-pulse.conf"
    dest: "/etc/pipewire/pipewire.conf.d/20-pipewire-pulse.conf"
    state: link

# TODO: Find way to install and enable pipewire-roc-sink module (and enable ~/.config/pipewire/pipewire.conf.d/roc-sink.conf)