// Copyright (C) 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include <functional>
#include <functional_test_utils/skip_tests_config.hpp>

#include "ie_core.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"

#include "common_test_utils/common_utils.hpp"
#include "functional_test_utils/layer_test_utils.hpp"

#include "single_layer_tests/transpose.hpp"

namespace LayerTestsDefinitions {

std::string TransposeLayerTest::getTestCaseName(testing::TestParamInfo<transposeParams> obj) {
    InferenceEngine::Precision netPrecision;
    std::vector<size_t> inputShapes, inputOrder;
    std::string targetDevice;
    std::tie(inputOrder, netPrecision, inputShapes, targetDevice) = obj.param;
    std::ostringstream result;
    result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_";
    result << "inputOrder=" << CommonTestUtils::vec2str(inputOrder) << "_";
    result << "netPRC=" << netPrecision.name() << "_";
    result << "targetDevice=" << targetDevice;
    return result.str();
}

void TransposeLayerTest::SetUp() {
    // TODO: Issue 32756
    // Failed to create function on SetUp stage with some parameters
    SKIP_IF_CURRENT_TEST_IS_DISABLED()
    SetRefMode(LayerTestsUtils::RefMode::CONSTANT_FOLDING);
    std::vector<size_t> inputShape, inputOrder;
    InferenceEngine::Precision netPrecision;
    std::tie(inputOrder, netPrecision, inputShape, targetDevice) = this->GetParam();

    auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
    auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
    auto paramOuts = ngraph::helpers::convert2OutputVector(
            ngraph::helpers::castOps2Nodes<ngraph::op::Parameter>(params));

    const auto inOrderShape = inputOrder.empty() ? ngraph::Shape({0}) : ngraph::Shape({inputShape.size()});
    const auto inputOrderOp = std::make_shared<ngraph::opset3::Constant>(ngraph::element::i64,
                                                                         inOrderShape,
                                                                         inputOrder);
    const auto transpose = std::make_shared<ngraph::opset3::Transpose>(paramOuts.at(0), inputOrderOp);
    const ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(transpose)};
    function = std::make_shared<ngraph::Function>(results, params, "Transpose");
}

TEST_P(TransposeLayerTest, CompareWithRefs) {
    Run();
};

}  // namespace LayerTestsDefinitions