from pytest import param


def test_match_pass():
    test_variables = "text, limit, output_crs, dataset, min_match, match_precision, classification_code, " \
                     "logical_status_code, country_code, expected_url, expected_params"
    test_data = [
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test", "maxresults": 100, "output_srs": "EPSG:27700", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            50,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 50, "output_srs": "EPSG:27700", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            "DPA",
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "dataset": "DPA", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            ("DPA", "LPI"),
            None,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "dataset": "DPA,LPI", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            0.5,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "minmatch": 0.5, "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            0.8,
            None,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "minmatch": 0.8, "offset": 0}
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            1,
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test", "maxresults": 100, "output_srs": "EPSG:27700", "matchprecision": "1", "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            "8",
            None,
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700", "matchprecision": "8", "offset": 0}
        ),
        param(
            "test3",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            "test1",
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test3", "maxresults": 100, "output_srs": "EPSG:27700", "fq": ["CLASSIFICATION_CODE:test1"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test1", "test2"),
            None,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["CLASSIFICATION_CODE:test1 CLASSIFICATION_CODE:test2"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            1,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["LOGICAL_STATUS_CODE:1"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            "J",
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["COUNTRY_CODE:J"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            ("L", "S"),
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["COUNTRY_CODE:L COUNTRY_CODE:S"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test1", "test2"),
            6,
            None,
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["CLASSIFICATION_CODE:test1 CLASSIFICATION_CODE:test2", "LOGICAL_STATUS_CODE:6"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test1", "test2"),
            None,
            "E",
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["CLASSIFICATION_CODE:test1 CLASSIFICATION_CODE:test2", "COUNTRY_CODE:E"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test1", "test2"),
            8,
            "M",
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["CLASSIFICATION_CODE:test1 CLASSIFICATION_CODE:test2", "LOGICAL_STATUS_CODE:8", "COUNTRY_CODE:M"], "offset": 0}
        ),
        param(
            "test2 test2 test2",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test1", "test2"),
            8,
            ("M", "N"),
            "https://api.os.uk/search/match/v1/match?key=test",
            {"query": "test2 test2 test2", "maxresults": 100, "output_srs": "EPSG:27700",
             "fq": ["CLASSIFICATION_CODE:test1 CLASSIFICATION_CODE:test2", "LOGICAL_STATUS_CODE:8",
                    "COUNTRY_CODE:M COUNTRY_CODE:N"],
             "offset": 0}
        ),

    ]
    return test_variables, test_data


def test_match_fail():
    test_variables = "text, limit, output_crs, dataset, min_match, match_precision, classification_code, " \
                     "logical_status_code, country_code, expected_error"
    test_data = [
        param(
            ("test", "test"),
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            -1000,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            "a",
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27701",
            None,
            None,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "test",
            None,
            None,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            "ABC",
            None,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            ("DPA", "ABC"),
            None,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            ("DPA", 3),
            None,
            None,
            None,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            -1,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            1.1,
            None,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            "test",
            None,
            None,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            "11",
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            11,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            0,
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            "0",
            None,
            None,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            1.5,
            None,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            16,
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            ("test", 16),
            None,
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            (1, 3),
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            2,
            None,
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            "test",
            None,
            TypeError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            "A",
            ValueError
        ),
        param(
            "test",
            100,
            "EPSG:27700",
            None,
            None,
            None,
            None,
            None,
            ("E", "A"),
            ValueError
        ),
    ]
    return test_variables, test_data

