name: macOS Build & Distribute (TestFlight / App Store)

on:
  workflow_dispatch:
    inputs:
      distribution:
        description: Where to distribute this build
        type: choice
        required: true
        options: [testflight, appstore]
        default: testflight

jobs:
  build_and_ship:
    runs-on: macos-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Upload to TestFlight
        if: ${{ inputs.distribution == 'testflight' }}
        uses: openMF/mifos-x-actionhub-publish-macos-on-appstore-testflight-kmp@v1.0.0
        with:
          app_identifier: 'org.mifospay'
          cmp_desktop_dir: 'cmp-desktop'
          keychain_name: signing.keychain-db           # optional
          java_version: '21'                           # optional (min 18)
          keychain_password: ${{ secrets.KEYCHAIN_PASSWORD }}
          certificates_password: ${{ secrets.CERTIFICATES_PASSWORD }}
          mac_app_distribution_certificate_b64: ${{ secrets.MAC_APP_DISTRIBUTION_CERTIFICATE_B64 }}
          mac_installer_distribution_certificate_b64: ${{ secrets.MAC_INSTALLER_DISTRIBUTION_CERTIFICATE_B64 }}
          mac_embedded_provision_b64: ${{ secrets.MAC_EMBEDDED_PROVISION_B64 }}
          mac_runtime_provision_b64: ${{ secrets.MAC_RUNTIME_PROVISION_B64 }}
          appstore_key_id: ${{ secrets.APPSTORE_KEY_ID }}
          appstore_issuer_id: ${{ secrets.APPSTORE_ISSUER_ID }}
          appstore_auth_key_b64: ${{ secrets.APPSTORE_AUTH_KEY }}

      - name: Submit to App Store (Production)
        if: ${{ inputs.distribution == 'appstore' }}
        uses: openMF/mifos-x-actionhub-publish-macos-on-appstore-kmp@v1.0.0
        with:
          app_identifier: 'org.mifospay'
          cmp_desktop_dir: 'cmp-desktop'
          keychain_name: signing.keychain-db           # optional
          java_version: '21'                           # optional (min 18)
          keychain_password: ${{ secrets.KEYCHAIN_PASSWORD }}
          certificates_password: ${{ secrets.CERTIFICATES_PASSWORD }}
          mac_app_distribution_certificate_b64: ${{ secrets.MAC_APP_DISTRIBUTION_CERTIFICATE_B64 }}
          mac_installer_distribution_certificate_b64: ${{ secrets.MAC_INSTALLER_DISTRIBUTION_CERTIFICATE_B64 }}
          mac_embedded_provision_b64: ${{ secrets.MAC_EMBEDDED_PROVISION_B64 }}
          mac_runtime_provision_b64: ${{ secrets.MAC_RUNTIME_PROVISION_B64 }}
          appstore_key_id: ${{ secrets.APPSTORE_KEY_ID }}
          appstore_issuer_id: ${{ secrets.APPSTORE_ISSUER_ID }}
          appstore_auth_key_b64: ${{ secrets.APPSTORE_AUTH_KEY }}
