﻿using System;
using System.Text;
using EasyApi.Formatting;
using EasyApi.Values;

namespace EasyApi.Metadata.Attributes.Formatting
{
	[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
	public sealed class StringResponseAttribute : MetadataAttribute
	{
		protected override ExtraProperty CreateMetadataProperty()
		{
			Encoding encoding = null;
			if (EncodingName != null)
			{
				encoding = Encoding.GetEncoding(EncodingName);
			}

			return MetadataProperties.ResponseContentFormatter.Create(new StringContentFormatter(encoding, MediaType));
		}

		public string EncodingName { get; set; }

		public string MediaType { get; set; }
	}
}