#
# Copyright 2025 Splunk Inc.
#
# 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.
#
from os.path import dirname, join, realpath

from splunk_add_on_ucc_framework.generators import GEN_FILE_LIST


def generate_docs() -> str:
    content = []
    content.append(
        """---
title: UCC framework generated files
---

The following table describes the files generated by UCC framework.
"""
    )
    content.append("| File Name  | File Location | File Description |")
    content.append("| ------------ | ------------ | ----------------- |")
    for file_name, file_class, file_path in GEN_FILE_LIST:
        content.append(
            f"| {file_name} | output/&lt;YOUR_ADDON_NAME&gt;/{'/'.join(file_path)} "
            f"| {file_class.__description__} |"
        )
    # statically appending this line as we are generating it now
    content.append(
        "| globalConfig.json | &lt;source_dir&gt; | "
        "Generates globalConfig.json file in the source code if globalConfig "
        "is not present in source directory at build time. |"
    )
    content.append("\n")
    return "\n".join(content)


def main() -> None:
    content = generate_docs()

    with open(
        join(
            realpath(dirname(dirname(dirname(__file__)))), "docs", "generated_files.md"
        ),
        "w",
    ) as writer:
        writer.write(content)


if __name__ == "__main__":
    main()
