// <copyright file="CSharpFileBuilder.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Text;

namespace LibraryVersionsGenerator;

internal abstract class CSharpFileBuilder
{
    internal StringBuilder Builder { get; } = new();

    public CSharpFileBuilder AddAutoGeneratedHeader()
    {
        Builder.AppendLine(@"//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the LibraryVersionsGenerator tool. To safely
//     modify this file, edit PackageVersionDefinitions.cs and
//     re-run the LibraryVersionsGenerator project in Visual Studio.
// 
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated. 
// </auto-generated>
//------------------------------------------------------------------------------
");
        return this;
    }

    public virtual CSharpFileBuilder BeginClass(string classNamespace, string className)
    {
        if (!string.IsNullOrEmpty(classNamespace))
        {
            Builder.AppendLine($"namespace {classNamespace};");
            Builder.AppendLine();
        }

        Builder.AppendLine(@"public static class LibraryVersion
{");

        return this;
    }

    public virtual CSharpFileBuilder EndClass()
    {
        Builder.AppendLine(@"}");

        return this;
    }

    public abstract CSharpFileBuilder BeginTestPackage(string testApplicationName, string integrationName);

    public abstract CSharpFileBuilder AddVersion(string version);

    public abstract CSharpFileBuilder EndTestPackage();

    public override string ToString()
    {
        return Builder.ToString();
    }
}
