# Maintainer: zxq5 <zxq5@proton.me>
pkgbase='damn-simple-architecture'
pkgname=('dsa' 'dsx' 'dsa-tools' 'dsx-server')
pkgver=0.1.1
pkgrel=1
startdir='.'
pkgdesc="Damn Simple Architecture"
arch=('x86_64')
url="https://git.zxq5.dev/zxq5/damn-simple-architecture"
license=('MIT')
makedepends=('rust' 'cargo' 'sed')

build() {
    cargo build --release \
        --bin dsa \
        --bin dsx \
        --bin dsa-a \
        --bin dsa-c \
        --bin dsx-server
}

package_dsa() {
    pkgdesc="DSA core binary"
    depends=()

    install -Dm755 "$startdir/target/release/dsa" "$pkgdir/usr/bin/dsa"
    install -Dm644 "$startdir/resources/dsa.desktop" \
        "$pkgdir/usr/share/applications/dsa.desktop"
    install -Dm644 "$startdir/resources/dsa.png" \
        "$pkgdir/usr/share/icons/hicolor/256x256/apps/dsa.png"
}

package_dsx() {
    pkgdesc="DSX client"
    depends=('dsa')

    install -Dm755 "$startdir/target/release/dsx" "$pkgdir/usr/bin/dsx"
}

package_dsa-tools() {
    pkgdesc="DSA assembler and compiler tools"
    depends=()

    install -Dm755 "$startdir/target/release/dsa-a" "$pkgdir/usr/bin/dsa-a"
    install -Dm755 "$startdir/target/release/dsa-c" "$pkgdir/usr/bin/dsa-c"
}

package_dsx-server() {
    pkgdesc="DSX server"
    depends=()

    install -Dm755 "$startdir/target/release/dsx-server" "$pkgdir/usr/bin/dsx-server"

    # Example sed usage — patch config paths for system install
    sed -i 's|./templates|/usr/share/dsx-server/templates|g' \
        "target/release/dsx-server" 2>/dev/null || true

    install -Dm644 "$startdir/dsx_server/templates" "$pkgdir/usr/share/dsx-server/templates" 2>/dev/null || true
}
