// Copyright © Selmo Technology GmbH. All Rights Reserved

using System.Text.Json.Serialization;

namespace SelmoStudio.Hmi.Server.Shared.Components.Chart.Models.Common
{
    public sealed class Axis
    {
        private Position _position;

        /// <summary>
        /// Gets or sets the begin at zero.
        /// </summary>
        /// <value>The begin at zero.</value>
        [JsonPropertyName("beginAtZero")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public bool? BeginAtZero { get; set; }

        /// <summary>
        /// Gets or sets the color.
        /// </summary>
        /// <value>The color.</value>
        [JsonPropertyName("color")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string? Color { get; set; }

        /// <summary>
        /// Gets or sets the display.
        /// </summary>
        /// <value>Display the axis or not</value>
        [JsonPropertyName("display")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public bool? Display { get; set; }

        /// <summary>
        /// Gets or sets the grid.
        /// </summary>
        /// <value>The grid.</value>
        [JsonPropertyName("grid")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public Grid? Grid { get; set; }

        /// <summary>
        /// Determines the maximum of the parameters.
        /// </summary>
        /// <value>The maximum.</value>
        [JsonPropertyName("max")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public double? Max { get; set; }

        /// <summary>
        /// Determines the minimum of the parameters.
        /// </summary>
        /// <value>The minimum.</value>
        [JsonPropertyName("min")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public double? Min { get; set; }

        /// <summary>
        /// Gets or sets the position.
        /// </summary>
        /// <value>The position.</value>
        [JsonIgnore]
        public Position Position
        {
            get => _position;
            set
            {
                _position = value;
                PositionString = _position.Value;
            }
        }

        /// <summary>
        /// Gets or sets the position.
        /// </summary>
        /// <value>The position.</value>
        [JsonPropertyName("position")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string? PositionString { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this axis is stacked.
        /// </summary>
        /// <value><c>true</c> if stacked; otherwise, <c>false</c>.</value>
        [JsonPropertyName("stacked")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public bool? Stacked { get; set; }

        /// <summary>
        /// Gets or sets the suggested maximum.
        /// </summary>
        /// <value>The suggested maximum.</value>
        [JsonPropertyName("suggestedMax")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public decimal? SuggestedMax { get; set; }

        /// <summary>
        /// Gets or sets the suggested minimum.
        /// </summary>
        /// <value>The suggested minimum.</value>
        [JsonPropertyName("suggestedMin")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public decimal? SuggestedMin { get; set; }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        [JsonPropertyName("Text")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string? Text { get; set; }

        /// <summary>
        /// Gets or sets the ticks.
        /// </summary>
        /// <value>The ticks.</value>
        [JsonPropertyName("ticks")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public Ticks? Ticks { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        [JsonPropertyName("title")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public AxesTitle? Title { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type.</value>
        [JsonPropertyName("type")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string? Type { get; set; }
    }
}