---
- name: Ensure workstation user directories exist
  tags: [dotfiles, dotfiles:workstation]
  ansible.builtin.file:
    path: "{{ item.path }}"
    state: directory
    owner: "{{ username }}"
    group: "{{ user_group }}"
    mode: "{{ item.mode }}"
  loop: "{{ workstation_user_directories | default([]) }}"
  loop_control:
    label: "{{ item.path }}"

- name: Copy workstation dotfiles
  tags: [dotfiles, dotfiles:workstation]
  ansible.builtin.copy:
    src: "{{ playbook_dir }}/../dotfiles/workstation/{{ item.src }}"
    dest: "{{ user_home }}/{{ item.dest }}"
    owner: "{{ username }}"
    group: "{{ user_group }}"
    mode: "{{ item.mode }}"
  loop: "{{ workstation_dotfiles | default([]) }}"
  loop_control:
    label: "{{ item.dest }}"

- name: Render workstation templates
  tags: [dotfiles, dotfiles:workstation]
  ansible.builtin.template:
    src: "{{ item.src }}"
    dest: "{{ user_home }}/{{ item.dest }}"
    owner: "{{ username }}"
    group: "{{ user_group }}"
    mode: "{{ item.mode }}"
  loop: "{{ workstation_templates | default([]) }}"
  loop_control:
    label: "{{ item.dest }}"

- name: Install workstation npm packages
  tags: [packages, npm]
  community.general.npm:
    name: "{{ item.name }}"
    global: true
    state: "{{ item.state | default('present') }}"
  become: true
  loop: "{{ workstation_npm_packages | default([]) }}"
  when:
    - workstation_manage_opencode | default(false)
    - workstation_npm_packages | length > 0
  loop_control:
    label: "{{ item.name }}"

- name: Install IBM Bob coding agent
  tags: [packages, ai_agents]
  ansible.builtin.shell: >
    curl -fsSL {{ workstation_ibm_bob_install_url }} | bash
  args:
    executable: /bin/bash
    creates: /usr/local/bin/bob
  become: true
  when:
    - workstation_manage_ibm_bob | default(false)
    - workstation_ibm_bob_install_url | length > 0
