---
- name: Ensure configuration directory is present
  ansible.builtin.file:
    path: '/etc/monica'
    state: directory
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  become: true

- name: Ensure Monica Quadlet file is present
  ansible.builtin.template:
    src: 'monica-app.container.j2'
    dest: '/home/debian/.config/containers/systemd/monica-app.container'
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  notify: 'restart monica'

- name: Ensure MariaDB Quadlet file is present
  ansible.builtin.template:
    src: 'monica-mariadb.container.j2'
    dest: '/home/debian/.config/containers/systemd/monica-mariadb.container'
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  notify: 'restart mariadb'

- name: Ensure Pod file is present
  ansible.builtin.copy:
    src: 'monica.pod'
    dest: '/home/debian/.config/containers/systemd/monica.pod'
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  notify: 'restart monica'

- name: Ensure Monica environment file is present
  ansible.builtin.template:
    src: 'monica.env.j2'
    dest: '/etc/monica/monica.env'
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  notify: 'restart monica'

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