---

- name: create obs directory
  file:
    dest: "{{ mixer_user.home }}/.config/obs-studio/{{ item }}"
    state: directory
    recurse: yes
    mode: u=rwx,g=rx,o=rx
  with_items:
    - basic/profiles/1080p
    - basic/profiles/720p
    - basic/scenes
  become: yes
  become_user: mixer

- name: create videos directory
  file:
    dest: "{{ mixer_user.home }}/Videos/{{ event.id }}/{{ room_id }}"
    state: directory
    recurse: yes
    mode: u=rwx,g=rx,o=rx
  become: yes
  become_user: mixer

- name: generate base obs configuration files
  template:
    src: "obs-studio/{{ item }}.j2"
    dest: "{{ mixer_user.home }}/.config/obs-studio/{{ item }}"
    mode: u=rw,g=r,o=r
  with_items:
    - global.ini
    - basic/profiles/1080p/basic.ini
    - basic/profiles/720p/basic.ini
    - basic/profiles/1080p/service.json
    - basic/profiles/720p/service.json
  become: yes
  become_user: mixer

- name: generate event obs configuration files
  template: 
    src: "obs-studio/basic/scenes/event_id.json.j2"
    dest: "{{ mixer_user.home }}/.config/obs-studio/basic/scenes/{{ event.id }}.json"
    mode: u=rw,g=r,o=r
  become: yes
  become_user: mixer

- name: ensure autostart folder exists
  file:
    path: "{{ mixer_user.home }}/.config/autostart"
    state: directory
  become: yes
  become_user: mixer

- name: automatically start OBS on login
  file:
    path: "{{ mixer_user.home }}/.config/autostart/obs-autostart.desktop"
    src: /usr/share/applications/obs.desktop
    state: link
  become: yes
  become_user: mixer
  when: autostart

- name: do not automatically start OBS on login
  file:
    path: "{{ mixer_user.home }}/.config/autostart/obs-autostart.desktop"
    state: absent
  become: yes
  become_user: mixer
  when: not autostart
