﻿//---------------------------------------------------------------------
// <copyright file="BadTypeReference.cs" company="Microsoft">
//      Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.OData.Edm.Validation;

namespace Microsoft.OData.Edm.Library
{
    internal class BadTypeReference : EdmTypeReference, IEdmCheckable
    {
        private readonly IEnumerable<EdmError> errors;

        public BadTypeReference(BadType definition, bool isNullable)
            : base(definition, isNullable)
        {
            this.errors = definition.Errors;
        }

        public IEnumerable<EdmError> Errors
        {
            get { return this.errors; }
        }

        public override string ToString()
        {
            EdmError error = this.Errors.FirstOrDefault();
            Debug.Assert(error != null, "error != null");
            string prefix = error != null ? error.ErrorCode.ToString() + ":" : "";
            return prefix + this.ToTraceString();
        }
    }
}
