using System.Text.Json.Serialization;

namespace MarcusLaw.OutlookAddin.Core.Models
{
    public sealed class EspoEntityRef
    {
        [JsonPropertyName("id")]
        public string Id { get; set; } = string.Empty;

        [JsonPropertyName("name")]
        public string? Name { get; set; }

        // EspoCRM's GlobalSearch and EmailAddress/search disagree on the
        // field name for entity type across versions — accept all three.
        [JsonPropertyName("entityType")]
        public string EntityType { get; set; } = string.Empty;

        [JsonPropertyName("entityName")]
        public string EntityNameAlias { set { if (!string.IsNullOrEmpty(value)) EntityType = value; } get => EntityType; }

        [JsonPropertyName("_scope")]
        public string ScopeAlias { set { if (!string.IsNullOrEmpty(value)) EntityType = value; } get => EntityType; }
    }
}
