<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
    <!-- Docker Publishing -->
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <!-- 
      Versioning - Semantic Versioning (https://semver.org/)
      Format: MAJOR.MINOR.PATCH
      - MAJOR: Breaking changes (incompatible API changes)
      - MINOR: New features (backward-compatible)
      - PATCH: Bug fixes (backward-compatible)
      
      Esempio workflow:
      - 1.0.0 -> 1.0.1 (bug fix)
      - 1.0.1 -> 1.1.0 (new feature)
      - 1.1.0 -> 2.0.0 (breaking change)
    -->
    <Version>1.5.1</Version>
    <AssemblyVersion>1.5.1.0</AssemblyVersion>
    <FileVersion>1.5.1.0</FileVersion>
    <!-- Assembly Information -->
    <Product>TradingBot</Product>
    <Description>Automated Crypto Trading Bot with Blazor UI</Description>
    <Copyright>Copyright ÃƒÆ’Ã†â€™ÃƒÂ¢Ã¢â€šÂ¬Ã…Â¡ÃƒÆ’Ã¢â‚¬Å¡Ãƒâ€šÃ‚Â© 2024 Alby96</Copyright>
    <Company>Alby96</Company>
    <Authors>Alby96</Authors>
    <!-- Build Metadata -->
    <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
    <Deterministic>true</Deterministic>
    <InformationalVersion>$(Version)+$(GITHUB_SHA)</InformationalVersion>
    <!-- Gitea Registry -->
    <ContainerRegistry>gitea.encke-hake.ts.net</ContainerRegistry>
    <ContainerRepository>alby96/encelado/tradingbot</ContainerRepository>
  </PropertyGroup>
  <!-- Folders for organization -->
  <ItemGroup>
    <Folder Include="Properties\PublishProfiles\" />
    <Folder Include="docs\deployment\" />
  </ItemGroup>
  <!--
    Post-Publish Target: Push to Gitea Container Registry
    
    Crea automaticamente 3 tag per ogni publish:
    1. latest - Sempre ultima versione
    2. {Version} - Versione semantica (es. 1.3.0)
    3. {Version}-{Date} - Versione + timestamp (es. 1.3.0-20241222)
    
    Condizioni di attivazione:
    - Configuration = Release
    - Non dentro container Docker
    - Profilo Docker in uso
    - Docker daemon running (verifica disponibilitÃƒÆ’Ã‚Â )
  -->
  <Target Name="PushToGiteaRegistry" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release' And '$(DOTNET_RUNNING_IN_CONTAINER)' != 'true' And '$(DockerPublish)' == 'true'">
    <PropertyGroup>
      <GiteaImage>$(ContainerRegistry)/$(ContainerRepository)</GiteaImage>
      <BuildDate>$([System.DateTime]::Now.ToString("yyyyMMdd"))</BuildDate>
      <VersionedTag>$(Version)-$(BuildDate)</VersionedTag>
    </PropertyGroup>
    <!-- Check if Docker is available -->
    <Exec Command="docker version" ContinueOnError="true" IgnoreExitCode="true">
      <Output TaskParameter="ExitCode" PropertyName="DockerExitCode" />
    </Exec>
    <!-- Only proceed if Docker is available -->
    <PropertyGroup>
      <DockerAvailable Condition="'$(DockerExitCode)' == '0'">true</DockerAvailable>
      <DockerAvailable Condition="'$(DockerExitCode)' != '0'">false</DockerAvailable>
    </PropertyGroup>
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="========================================" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="ÃƒÂ¢Ã…Â¡Ã‚Â ÃƒÂ¯Ã‚Â¸Ã‚Â  Docker Not Available" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="========================================" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="Docker daemon is not running or Docker Desktop is not started." />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="ÃƒÂ°Ã…Â¸Ã¢â‚¬Å“Ã¢â‚¬Â¹ To enable Gitea Registry push:" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="   1. Start Docker Desktop" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="   2. Wait for Docker to be ready" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="   3. Run Publish again" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ Compilation successful - application ready to run locally" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="ÃƒÂ¢Ã‚ÂÃ‚Â­ÃƒÂ¯Ã‚Â¸Ã‚Â  Skipping Gitea Registry push" />
    <Message Condition="'$(DockerAvailable)' != 'true'" Importance="high" Text="" />
    <!-- Only execute Docker commands if Docker is available -->
    <CallTarget Condition="'$(DockerAvailable)' == 'true'" Targets="ExecuteGiteaPush" />
  </Target>
  <Target Name="ExecuteGiteaPush">
    <PropertyGroup>
      <GiteaImage>$(ContainerRegistry)/$(ContainerRepository)</GiteaImage>
      <BuildDate>$([System.DateTime]::Now.ToString("yyyyMMdd"))</BuildDate>
      <VersionedTag>$(Version)-$(BuildDate)</VersionedTag>
    </PropertyGroup>
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="========================================" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã‚ÂÃ‚Â³ Gitea Container Registry Push" />
    <Message Importance="high" Text="========================================" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã¢â‚¬Å“Ã‚Â¦ Version: $(Version)" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã¢â‚¬Å“Ã¢â‚¬Â¦ Build Date: $(BuildDate)" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã‚ÂÃ‚Â·ÃƒÂ¯Ã‚Â¸Ã‚Â  Creating tags..." />
    <!-- Tag 1: latest -->
    <Exec Command="docker tag tradingbot:latest $(GiteaImage):latest" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ latest" />
    <!-- Tag 2: Version (semantic) -->
    <Exec Command="docker tag tradingbot:latest $(GiteaImage):$(Version)" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ $(Version)" />
    <!-- Tag 3: Version-Date -->
    <Exec Command="docker tag tradingbot:latest $(GiteaImage):$(VersionedTag)" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ $(VersionedTag)" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã…Â¡Ã¢â€šÂ¬ Pushing to $(ContainerRegistry)..." />
    <!-- Push all tags -->
    <Exec Command="docker push $(GiteaImage):latest" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ Pushed: latest" />
    <Exec Command="docker push $(GiteaImage):$(Version)" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ Pushed: $(Version)" />
    <Exec Command="docker push $(GiteaImage):$(VersionedTag)" />
    <Message Importance="high" Text="   ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ Pushed: $(VersionedTag)" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="========================================" />
    <Message Importance="high" Text="ÃƒÂ¢Ã…â€œÃ¢â‚¬Â¦ Successfully pushed to Gitea Registry!" />
    <Message Importance="high" Text="========================================" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã¢â‚¬Å“Ã‚Â¦ Published images:" />
    <Message Importance="high" Text="   - $(GiteaImage):latest" />
    <Message Importance="high" Text="   - $(GiteaImage):$(Version)" />
    <Message Importance="high" Text="   - $(GiteaImage):$(VersionedTag)" />
    <Message Importance="high" Text="" />
    <Message Importance="high" Text="ÃƒÂ°Ã…Â¸Ã¢â‚¬ÂÃ¢â‚¬â€ Verify at:" />
    <Message Importance="high" Text="   https://$(ContainerRegistry)/Alby96/Encelado/-/packages" />
    <Message Importance="high" Text="" />
  </Target>
</Project>