﻿using System.Collections.Generic;
using Microsoft.Extensions.Primitives;

namespace AspNetCore.RequestLogger.Metadata
{
    /// <summary>
    ///     <inheritdoc cref="IResponseData" />
    /// </summary>
    internal class ResponseData : IResponseData
    {
        private readonly Dictionary<string, StringValues> _headers;

        /// <summary>
        ///     Initializes a new instance of the <see cref="ResponseData" /> class.
        /// </summary>
        public ResponseData()
        {
            _headers = new Dictionary<string, StringValues>();
        }

        /// <summary>
        ///     <inheritdoc cref="IResponseData.ContentLength" />
        /// </summary>
        public long? ContentLength { get; set; }

        /// <summary>
        ///     <inheritdoc cref="IResponseData.ContentType" />
        /// </summary>
        public string ContentType { get; set; }

        /// <summary>
        ///     <inheritdoc cref="IResponseData.StatusCode" />
        /// </summary>
        public int StatusCode { get; set; }

        /// <summary>
        ///     <inheritdoc cref="IResponseData.Body" />
        /// </summary>
        public string Body { get; set; }

        /// <summary>
        ///     <inheritdoc cref="IResponseData.Headers" />
        /// </summary>
        public IReadOnlyDictionary<string, StringValues> Headers => _headers;

        /// <summary>
        ///     Adds the specified header value to the response's metadata.
        /// </summary>
        /// <param name="key">The key or name of the header.</param>
        /// <param name="value">The value of the header.</param>
        public void AddHeader(string key, StringValues value)
        {
            _headers.Add(key, value);
        }
    }
}