- name: Ensure immich directories have correct permissions
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    mode: "0755"
    owner: "debian"
    group: "debian"
  become: true
  loop:
    - "{{ immich_upload_dir }}"
    - "{{ immich_postgres_dir }}"

- name: Ensure system Quadlet directory is present
  ansible.builtin.file:
    path: /etc/containers/systemd
    state: directory
    owner: root
    group: root
    mode: "0755"
  become: true

- name: Ensure ML container system Quadlet is present
  ansible.builtin.template:
    src: immich-ml.container.j2
    dest: /etc/containers/systemd/immich-ml.container
    owner: root
    group: root
    mode: "0644"
  become: true
  notify: restart immich-ml

# - name: Ensure user Quadlet files are present (templates)
#   ansible.builtin.template:
#     src: "{{ item }}.j2"
#     dest: "/home/debian/.config/containers/systemd/{{ item }}"
#     mode: "0644"
#     owner: "debian"
#     group: "debian"
#   become: true
#   loop:
#     - immich-app.container
#     - immich-postgres.container
#   notify: restart immich

# - name: Ensure user Quadlet files are present (static)
#   ansible.builtin.copy:
#     src: "{{ item }}"
#     dest: "/home/debian/.config/containers/systemd/{{ item }}"
#     mode: "0644"
#     owner: "debian"
#     group: "debian"
#   become: true
#   loop:
#     - immich-redis.container
#     - immich.pod
#   notify: restart immich

# - name: Ensure Caddyfile is present
#   ansible.builtin.copy:
#     src: immich.Caddyfile
#     dest: /etc/caddy/immich.Caddyfile
#     owner: root
#     group: root
#     mode: "0644"
#   become: true
#   notify: reload caddy
