version: 1.0.0

registerApp:
{{#if activePlugins.fx-resource-aad-app-for-teams}}
  - uses: aadApp/create # Creates a new AAD app to authenticate users if AAD_APP_CLIENT_ID environment variable is empty
    with:
      name: {{aadAppName}} # Note: when you run configure/aadApp, the AAD app name will be updated based on the definition of manifest. If you don't want to change the name, ensure the name in AAD manifest is same with the name defined here.
      generateClientSecret: true # If the value is false, the action will not generate client secret for you
    # Output: following environment variable will be persisted in current environment's .env file.
    # AAD_APP_CLIENT_ID: the client id of AAD app
    # AAD_APP_CLIENT_SECRET: the client secret of AAD app
    # AAD_APP_OBJECT_ID: the object id of AAD app
    # AAD_APP_TENANT_ID: the tenant id of AAD app
    # AAD_APP_OAUTH_AUTHORITY_HOST: the host of OAUTH authority of AAD app
    # AAD_APP_OAUTH_AUTHORITY: the OAUTH authority of AAD app
{{/if}}
  - uses: teamsApp/create # Creates a Teams app
    with:
      name: {{teamsAppName}} # Teams app name
    # Output: following environment variable will be persisted in current environment's .env file.
    # TEAMS_APP_ID: the id of Teams app

{{#if activePlugins.fx-resource-bot}}
provision:
  - uses: botAadApp/create # Creates a new AAD app for Bot Registration.
    with:
      name: {{appName}}
    # Output: following environment variable will be persisted in current environment's .env file.
    # BOT_ID: the AAD app client id created for Bot Registration.
    # SECRET_BOT_PASSWORD: the AAD app client secret created for Bot Registration.
  - uses: botFramework/create # Create or update the bot registration on dev.botframework.com
    with:
      botId: $\{{BOT_ID}}
      name: {{appName}}
      messagingEndpoint: $\{{BOT_ENDPOINT}}/api/messages
      description: ""
  - uses: file/updateAppSettings
    with:
      target: ./appsettings.Development.json
      appsettings:
        BOT_ID: $\{{BOT_ID}}
        BOT_PASSWORD: $\{{SECRET_BOT_PASSWORD}}
  {{#if activePlugins.fx-resource-aad-app-for-teams}}
        TeamsFx:
          Authentication:
            ClientId: $\{{AAD_APP_CLIENT_ID}}
            ClientSecret: $\{{SECRET_AAD_APP_CLIENT_SECRET}}
            OAuthAuthority: $\{{AAD_APP_OAUTH_AUTHORITY}}
  {{/if}}
{{/if}}

configureApp:
{{#if activePlugins.fx-resource-frontend-hosting}}
  - uses: file/updateEnv # Generate env to .env file
    with:
      envs:
        {{placeholderMappings.tabDomain}}: localhost:44302
        {{placeholderMappings.tabEndpoint}}: https://localhost:44302
        {{placeholderMappings.tabIndexPath}}: '#'
  {{#if activePlugins.fx-resource-aad-app-for-teams}}
  - uses: file/updateAppSettings
    with:
      target: ./appsettings.Development.json
      appsettings:
        TeamsFx:
          Authentication:
            ClientId: $\{{AAD_APP_CLIENT_ID}}
            ClientSecret: $\{{SECRET_AAD_APP_CLIENT_SECRET}}
            OAuthAuthority: $\{{AAD_APP_OAUTH_AUTHORITY}}
  {{/if}} 
{{/if}}
{{#if activePlugins.fx-resource-bot}}
  - uses: file/updateEnv # Generate env to .env file
    with:
      envs:
        {{placeholderMappings.botDomain}}: $\{{BOT_DOMAIN}}
{{/if}}
{{#if activePlugins.fx-resource-aad-app-for-teams}}
  - uses: aadApp/update # Apply the AAD manifest to an existing AAD app. Will use the object id in manifest file to determine which AAD app to update.
    with:
      manifestPath: ./aad.manifest.template.json # Relative path to this file. Environment variables in manifest will be replaced before apply to AAD app
      outputFilePath : ./build/aad.manifest.$\{{TEAMSFX_ENV}}.json
  # Output: following environment variable will be persisted in current environment's .env file.
  # AAD_APP_ACCESS_AS_USER_PERMISSION_ID: the id of access_as_user permission which is used to enable SSO
{{/if}}
  - uses: teamsApp/validate
    with:
      manifestPath: ./appPackage/manifest.json # Path to manifest template
  - uses: teamsApp/zipAppPackage # Build Teams app package with latest env value
    with:
      manifestPath: ./appPackage/manifest.json # Path to manifest template
      outputZipPath: ./build/appPackage/appPackage.$\{{TEAMSFX_ENV}}.zip
      outputJsonPath: ./build/appPackage/manifest.$\{{TEAMSFX_ENV}}.json
  - uses: teamsApp/update # Apply the Teams app manifest to an existing Teams app. Will use the app id in manifest file to determine which Teams app to update.
    with:
      appPackagePath: ./build/appPackage/appPackage.$\{{TEAMSFX_ENV}}.zip # Relative path to this file. This is the path for built zip file.
    # Output: following environment variable will be persisted in current environment's .env file.
    # TEAMS_APP_ID: the id of Teams app