#! /etc/profiles/per-user/jawz/bin/bash
#! nix-shell -i bash -p bash

manga_dir="/srv/pool/multimedia/media/Library/manga/manga"

airing=()
completed=()
update_volumes=()
other=()

categorize_series() {
    local series_dir="$1"
    local has_ch=false
    local has_vol=false

    for file in "$series_dir"/*; do
        if [[ $(basename "$file") == *"Ch."* ]]; then
            has_ch=true
        elif [[ $(basename "$file") == *"Vol."* ]]; then
            has_vol=true
        fi
    done

    if $has_ch && $has_vol; then
        update_volumes+=("$(basename "$series_dir")")
    elif $has_ch; then
        airing+=("$(basename "$series_dir")")
    elif $has_vol; then
        completed+=("$(basename "$series_dir")")
    else
        other+=("$(basename "$series_dir")")
    fi
}

for series in "$manga_dir"/*; do
    if [ ! -d "$series" ]; then
        continue
    fi
    categorize_series "$series"
done

echo "=== Categorized Manga Series ==="
echo "Airing:"
for series in "${airing[@]}"; do
    echo "  - $series"
done

echo "Completed:"
for series in "${completed[@]}"; do
    echo "  - $series"
done

echo "Update Volumes:"
for series in "${update_volumes[@]}"; do
    echo "  - $series"
done

echo "Other:"
for series in "${other[@]}"; do
    echo "  - $series"
done
