﻿namespace PackageManager.Models
{
    using System;
    using Common;
    using Contracts;
    using Enums;

    public class PackageVersion : IVersion
    {
        private int major;
        private int minor;
        private int patch;
        private VersionType versionType;

        /// <summary>
        /// Initialize a new instance of <see cref="PackageVersion"/>
        /// </summary>
        /// <param name="major">Package version major.</param>
        /// <param name="minor">Package version minor.</param>
        /// <param name="patch">Package version patch</param>
        /// <param name="type">Version type.</param>
        public PackageVersion(int major, int minor, int patch, VersionType type)
        {
            this.Major = major;
            this.Minor = minor;
            this.Patch = patch;
            this.VersionType = type;
        }

        /// <summary>
        /// Package manager major.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        public int Major
        {
            get => this.major;

            private set
            {
                Validator.CheckIfLessThanZero(value);
                this.major = value;
            }
        }

        /// <summary>
        /// Package manager minor.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        public int Minor
        {
            get => this.minor;

            private set
            {
                Validator.CheckIfLessThanZero(value);
                this.minor = value;
            }
        }

        /// <summary>
        /// Package manager patch.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        public int Patch
        {
            get => this.patch;

            private set
            {
                Validator.CheckIfLessThanZero(value);
                this.patch = value;
            }
        }

        /// <summary>
        /// Version type.
        /// </summary>
        public VersionType VersionType
        {
            get => this.versionType;

            private set
            {
                if (!Enum.IsDefined(typeof(VersionType), value))
                {
                    throw new ArgumentException();
                }

                this.versionType = value;
            }
        }
    }
}