// Copyright [2026] [Argus]
//
// 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.

//go:build unit || integration

package v1

import (
	"os"
	"path/filepath"
	"strings"

	"github.com/release-argus/Argus/internal/test"
)

func writeFile(path string, data string) {
	data = strings.TrimPrefix(data, "\n")
	_ = os.WriteFile(path, []byte(data), 0644)
}

func testYAML_Argus(path string) {
	// Keep the DB beside rhe config.
	dbFile := strings.TrimSuffix(path, filepath.Ext(path)) + ".db"

	data := test.TrimYAML(`
		defaults:
			service:
				latest_version:
					access_token: ${GITHUB_TOKEN}
			notify:
				gotify:
					options:
						message: hi
			webhook:
				desired_status_code: 0
		settings:
			data:
				database_file: ` + dbFile + `
			web:
				listen_port: 0
		service:
			test:
				comment: foo
				latest_version:
					type: github
					url: ` + test.ArgusGitHubRepo + `
	`)

	writeFile(path, data)
}
