#!/usr/bin/env bash

# # Check the status of the git submodules
git submodule status

# # Create necessary directories
mkdir -p docs/tech
mkdir -p files-from-repos

# Copy files to the respective directories
cp ./backend/definitions/README.md ./docs/tech/architecture/definitions/README.md
cp ./backend/definitions/CHANGELOG.md ./docs/tech/architecture/definitions/CHANGELOG.md
cp ./backend/openapi.yml ./docs/tech/api/openapi.yml

# Copy definitions from definition registry
cp ./definition-registry/showcase-definition.zip ./files-from-repos/showcase-definition.zip
cp ./definition-registry/introductory-definition.zip ./files-from-repos/intro-definition.zip
cp ./definition-registry/phishing-uni.zip ./files-from-repos/phishing-uni.zip
cp ./definition-registry/phone-loss.zip ./files-from-repos/phone-loss.zip
cp ./definition-registry/insider-threat.zip ./files-from-repos/insider-threat.zip
cp ./definition-registry/security-training-call.zip ./files-from-repos/security-training-call.zip
cp ./definition-registry/security-training-notebook.zip ./files-from-repos/security-training-notebook.zip
cp ./definition-registry/security-training-phishing.zip ./files-from-repos/security-training-phishing.zip

# Add the header section of a definition changelog
cd ./docs/tech/architecture/definitions
cat changelog_header.txt CHANGELOG.md > temp_changelog.md
mv temp_changelog.md CHANGELOG.md
cd ../../../..  # Return to the main directory

# Remove "Issues: " lines from the changelog
sed -i '/^Issues: /d' ./docs/tech/architecture/definitions/CHANGELOG.md

# Copy files from the docker-deployment repository
cp ./docker-deployment/users.md ./docs/tech/installation/users.md
cp ./docker-deployment/troubleshooting.md ./docs/tech/installation/troubleshooting.md
cp ./docker-deployment/README.md ./docs/tech/installation/setup.md
cp ./docker-deployment/installation.md ./docs/tech/installation/overview.md
cp ./docker-deployment/https-owncert/README.md ./docs/tech/installation/https/owncert.md
cp ./docker-deployment/https/README.md ./docs/tech/installation/https/base-setup.md
