name: Smart Deploy (Mobile)
on:
  push:
    branches: ["main"] #, "develop"] # develop 브랜치 추가하면 변경

jobs:
  fingerprint:
    name: Fingerprint
    type: fingerprint
    environment: preview # ${{ github.ref_name == 'main' && 'production' || 'preview' }} 

  get_android_build:
    name: Check for existing android build
    needs: [fingerprint]
    type: get-build
    params:
      fingerprint_hash: ${{ needs.fingerprint.outputs.android_fingerprint_hash }}
      profile: preview # ${{ github.ref_name == 'main' && 'production' || 'preview' }} 

  # TODO: 추후 ios 추가 후 주석 제거

  # get_ios_build:
  #   name: Check for existing ios build
  #   needs: [fingerprint]
  #   type: get-build
  #   params:
  #     fingerprint_hash: ${{ needs.fingerprint.outputs.ios_fingerprint_hash }}
  #     profile: ${{ github.ref_name == 'main' && 'production' || 'preview' }} 

  build_android:
    name: Build Android
    needs: [get_android_build]
    if: ${{ !needs.get_android_build.outputs.build_id }}
    type: build
    params:
      platform: android
      profile: preview # ${{ github.ref_name == 'main' && 'production' || 'preview' }} 

  # build_ios:
  #   name: Build iOS
  #   needs: [get_ios_build]
  #   if: ${{ !needs.get_ios_build.outputs.build_id }}
  #   type: build
  #   params:
  #     platform: ios
  #     profile: ${{ github.ref_name == 'main' && 'production' || 'preview' }} 

  publish_android_update:
    name: Publish Android update
    needs: [get_android_build]
    if: ${{ needs.get_android_build.outputs.build_id }}
    type: update
    params:
      channel: staging # ${{ github.ref_name == 'main' && 'production' || 'staging' }} 
      platform: android 

  # publish_ios_update:
  #   name: Publish iOS update
  #   needs: [get_ios_build]
  #   if: ${{ needs.get_ios_build.outputs.build_id }}
  #   type: update
  #   params:
  #     channel: ${{ github.ref_name == 'main' && 'production' || 'staging' }} 
  #     platform: ios
