# Copyright 2024 The Pigweed 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
#
#     https://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 __future__ import annotations

from PB.recipe_modules.pigweed.bazel_roll.tests.full import InputProperties
from recipe_engine import post_process

DEPS = [
    "fuchsia/gitiles",
    "fuchsia/roll_commit_message",
    "pigweed/bazel_roll",
    "pigweed/checkout",
    "recipe_engine/properties",
    "recipe_engine/step",
]

PROPERTIES = InputProperties


def RunSteps(  # pylint: disable=invalid-name
    api: recipe_api.RecipeScriptApi,
    props: InputProperties,
):
    checkout = api.checkout.fake_context()

    assert len(props.git_repositories) == 1

    rolls = api.bazel_roll.update_git_repository(
        checkout=checkout,
        git_repository=props.git_repositories[0],
    )

    pres = api.step.empty('commit message').presentation
    pres.step_summary_text = api.roll_commit_message.format(
        *rolls,
        roll_prefix='roll:',
        send_comment=True,
    )


def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]:
    """Create tests."""

    def _url(x: str = 'pigweed/pigweed'):
        assert ':' not in x
        return f'https://pigweed.googlesource.com/{x}'

    def trigger(url, **kwargs):
        return api.checkout.ci_test_data(git_repo=_url(url), **kwargs)

    def properties(repo: GitRepository, **kwargs):
        props = InputProperties(**kwargs)
        props.git_repositories.append(repo)
        return api.properties(props)

    yield api.test(
        'success',
        properties(api.bazel_roll.git_repo()),
        trigger('pigweed/pigweed'),
        api.gitiles.log("pigweed.log pigweed", "A"),
    )

    yield api.test(
        'unrecognized-remote',
        properties(api.bazel_roll.git_repo(remote=_url('unrecognized-remote'))),
        trigger('unrecognized-remote'),
        api.post_process(
            post_process.MustRun,
            'unrecognized-remote.failed to update commit hash',
        ),
        status='FAILURE',
    )

    yield api.test(
        'bad-trigger',
        properties(
            api.bazel_roll.git_repo(
                remote=_url('foo'),
                workspace_path='bar/WORKSPACE',
            ),
        ),
        trigger('bar'),
        status='FAILURE',
    )

    yield api.test(
        'no-trigger',
        properties(api.bazel_roll.git_repo()),
        api.gitiles.log("pigweed.log pigweed", "A"),
    )

    yield api.test(
        'backwards',
        properties(api.bazel_roll.git_repo()),
        api.gitiles.log("pigweed.log pigweed", "A", n=0),
    )
