#!/usr/bin/env python3

import argparse
import json
import re


parser = argparse.ArgumentParser()
parser.add_argument('-b', '--base', default=None, required=True)
parser.add_argument('-f', '--file', default=None, required=True)
args = parser.parse_args()

with open(args.file) as error_file:
    error_data = error_file.readlines()

    with open(args.base) as base_file:
        base_json = json.load(base_file)
        for message_name, message_data in base_json['Messages'].items():
            message_id = base_json['RegistryPrefix'] + '.' + \
                base_json['RegistryVersion'] + '.' + message_name
            message_found = False
            index = 0
            for i, error in enumerate(error_data):
                if message_id in error:
                    message_found = True
                    index = i
                    break
            if not message_found:
                print("{} not found".format(message_id))
                continue

            error_info = error_data[index:index + 15]
            error_str = " ".join(error_info)
            error_str = re.sub(
                'std::to_string\\(arg(\\d+)\\)',
                'arg\\1',
                error_str)
            error_str = re.sub('"\n\\s*"', '', error_str, re.MULTILINE)
            error_str = re.sub(
                '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"',
                '%\\1',
                error_str,
                re.MULTILINE)
            if message_data['Message'] not in error_str:
                print(
                    "{}: error in Message: {}".format(
                        message_id,
                        message_data['Message']))
                print(error_str)

            if message_data['MessageSeverity'] not in error_str:
                print("{}: error in MessageSeverity: {}".format(
                    message_id, message_data['MessageSeverity']))
                print(error_str)

            if message_data['Resolution'] not in error_str:
                print(
                    "{}: error in Resolution: {}".format(
                        message_id,
                        message_data['Resolution']))
                print(error_str)
