using StructureHelper.Windows.MainWindow.Materials;
using StructureHelper.Windows.UserControls;
using StructureHelper.Windows.ViewModels;
using StructureHelperLogics.Models.BeamShears;
using System.Windows.Media;

namespace StructureHelper.Windows.BeamShears
{
    public class StirrupByInclinedRebarViewModel : OkCancelViewModelBase
    {
        private const double minTransferLengthValue = 0.01;
        private readonly IStirrupByInclinedRebar stirrupByInclinedRebar;
        private PrimitiveVisualPropertyViewModel visual;

        public string Name
        {
            get => stirrupByInclinedRebar.Name;
            set
            {
                stirrupByInclinedRebar.Name = value;
                OnPropertyChanged(nameof(Name));
            }
        }

        public double CompressedGap
        {
            get => stirrupByInclinedRebar.CompressedGap;
            set
            {
                stirrupByInclinedRebar.CompressedGap = value;
                OnPropertyChanged(nameof(CompressedGap));
            }
        }

        public double StartCoordinate
        {
            get => stirrupByInclinedRebar.StartCoordinate;
            set
            {
                stirrupByInclinedRebar.StartCoordinate = value;
                OnPropertyChanged(nameof(StartCoordinate));
            }
        }

        public double AngleOfInclination
        {
            get => stirrupByInclinedRebar.AngleOfInclination;
            set
            {
                stirrupByInclinedRebar.AngleOfInclination = value;
                OnPropertyChanged(nameof(AngleOfInclination));
            }
        }

        public double TransferLength
        {
            get => stirrupByInclinedRebar.TransferLength;
            set
            {
                if (value < minTransferLengthValue) { value = minTransferLengthValue; }
                stirrupByInclinedRebar.TransferLength = value;
                OnPropertyChanged(nameof(TransferLength));
            }
        }

        public double LegCount
        {
            get => stirrupByInclinedRebar.LegCount;
            set
            {
                if (value < 0.0) { value = 0.0; }
                stirrupByInclinedRebar.LegCount = value;
                OnPropertyChanged(nameof(LegCount));
            }
        }

        public RebarSectionViewModel RebarSectionViewModel {get;}
        public PrimitiveVisualPropertyViewModel VisualProperty
        {
            get => visual;
            private set
            {
                visual = value;
                OnPropertyChanged(nameof(VisualProperty));
            }
        }

        public StirrupByInclinedRebarViewModel(IStirrupByInclinedRebar stirrupByInclinedRebar)
        {
            this.stirrupByInclinedRebar = stirrupByInclinedRebar;
            RebarSectionViewModel = new(this.stirrupByInclinedRebar.RebarSection)
            {
                MinRebarDiameter = 0.003,
                MaxRebarDiameter = 0.032
            };
            VisualProperty = new(this.stirrupByInclinedRebar.VisualProperty);
        }
    }
}
