#!/bin/bash

# 1. Initialize the CAN 2025 Project
mkdir can-2025-morocco
cd can-2025-morocco
git init -b main

# Configure dummy identity for the "Previous Assistant Coach"
git config user.email "assistant@frmf.ma"
git config user.name "Assistant Coach"

# 2. Initial Setup: Host Cities and Stadiums
mkdir infrastructure
echo "- Rabat: Prince Moulay Abdellah" > infrastructure/stadiums.txt
echo "- Casablanca: Stade Mohammed V" >> infrastructure/stadiums.txt
echo "- Tangier: Ibn Batouta" >> infrastructure/stadiums.txt
echo "- Marrakech: Grand Stade" >> infrastructure/stadiums.txt
git add .
git commit -m "Setup: Confirmed host cities for CAN 2025"

# 3. Squad Selection (The "Good" State)
echo "GK: Yassine Bounou" > starting_xi.txt
echo "DF: Achraf Hakimi" >> starting_xi.txt
echo "DF: Nayef Aguerd" >> starting_xi.txt
echo "MF: Sofyan Amrabat" >> starting_xi.txt
echo "FW: Brahim Diaz" >> starting_xi.txt
echo "FW: Soufiane Rahimi" >> starting_xi.txt
git add starting_xi.txt
git commit -m "Squad: Registered official player list"

# 4. The Disaster: Accidental Deletion of Star Player
# (Simulating deleting a critical file)
grep -v "Hakimi" starting_xi.txt > starting_xi_temp.txt && mv starting_xi_temp.txt starting_xi.txt
git add starting_xi.txt
git commit -m "Update: Adjusted defensive line (Oops)"

# 5. Parallel Strategy (Branching)
# Create a new branch for an experimental attacking formation
git checkout -b strategy/attack-overload
echo "Formation: 4-3-3 Attack" > tactics.txt
echo "Instruction: High Pressing" >> tactics.txt
git add tactics.txt
git commit -m "Tactics: Defined attacking strategy for Group Stage"

# 6. Conflict Setup (Back on Main)
git checkout main
echo "Formation: 5-4-1 Park the Bus" > tactics.txt
git add tactics.txt
git commit -m "Tactics: Defined defensive strategy for Opening Match"

# 7. Create the Mission Instructions (README)
cat <<'EOT' > README.md
# 🦁 Operation Atlas Lions: CAN 2025 DevOps Edition

**Location:** Prince Moulay Abdellah Stadium, Rabat.
**Time:** T-Minus 2 Hours to Kickoff.
**Status:** TACTICAL CHAOS.

## 📋 Mission Objectives (Git Exercises)

### Task 1: The Missing Star (Git Log & Checkout)
The previous assistant accidentally removed **Achraf Hakimi** from the `starting_xi.txt`.
1. Run `git log` to find the commit where the squad was "Registered official player list".
2. Find the **Commit Hash**.
3. Bring the file back from the past using: 
   `git checkout <COMMIT_HASH> -- starting_xi.txt`
4. Verify Hakimi is back in the file.
5. Commit the fix: `git commit -am "Fix: Restored Hakimi to starting XI"`.

### Task 2: The Tactical Merge (Branching & Merging)
We have a divergent strategy. The main branch wants to play defensive ("Park the Bus"), but the fans want the attacking style from the `strategy/attack-overload` branch.
1. We decide to go with the ATTACK.
2. Merge the attacking branch into main:
   `git merge strategy/attack-overload`
3. **CONFLICT ALERT!** Both branches created `tactics.txt` with different content.
4. Open `tactics.txt`. You will see conflict markers (`<<<<<<`, `======`, `>>>>>>`).
5. Delete the defensive lines and keep the **Attacking** lines. Remove the markers.
6. Save the file and finalize the merge:
   `git add tactics.txt`
   `git commit -m "Merge: Finalized attacking formation"`

### Task 3: The Last Minute Change (Staging)
The coach wants to add a motivational quote to the locker room.
1. Create a file `locker_room.md` and add: "Dima Maghrib!".
2. Add it to the staging area: `git add locker_room.md`.
3. **Wait!** The coach changed his mind. Unstage the file (do not delete it, just remove from staging):
   `git restore --staged locker_room.md`
   
**Good luck. The stadium is full. Don't crash the server (or the match).**
EOT

git add README.md
git commit -m "Docs: Printed tactical instructions for the new Engineer"

echo "-----------------------------------------------------------"
echo "   🇲🇦 CAN 2025 Repository Ready!"
echo "   Folder: can-2025-morocco"
echo "   Mission: Fix the squad before kickoff."
echo "-----------------------------------------------------------"
