﻿// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace OpenAPI.Validator.JsonConverters
{
    public abstract class SwaggerJsonConverter : JsonConverter
    {
        protected JObject Document { get; set; }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }

        protected JsonSerializerSettings GetSettings(JsonSerializer serializer)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.None,
                MetadataPropertyHandling = MetadataPropertyHandling.Ignore
            };
            foreach (var converter in serializer.Converters)
            {
                if (converter != this)
                {
                    settings.Converters.Add(converter);
                }
            }
            return settings;
        }
    }
}