<commit_before>﻿using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
using Skybrud.LinkPicker.Json.Converters;
using Umbraco.Core.Models;
using Umbraco.Web;

namespace Skybrud.LinkPicker {

    /// <summary>
    /// Class representing a single link item.
    /// </summary>
    [JsonConverter(typeof(LinkPickerConverter))]
    public class LinkPickerItem {

        private string _url;

        #region Properties

        /// <summary>
        /// Gets a reference to the <see cref="JObject"/> the item was parsed from.
        /// </summary>
        [JsonIgnore]
        public JObject JObject { get; private set; }

        /// <summary>
        /// Gets the ID of the selected content or media. If an URL has been selected, this will return <code>0</code>.
        /// </summary>
        [JsonProperty("id")]
        public int Id { get; private set; }

        /// <summary>
        /// Gets the name of the link.
        /// </summary>
        [JsonProperty("name")]
        public string Name { get; private set; }

        /// <summary>
        /// Gets the URL of the link. Since the URL of a content or media item may change over time (eg. if renamed or
        /// moved), this property will attempt to retrieve the current URL from the relevant Umbraco cache.
        /// 
        /// If <see cref="Mode"/> is <see cref="LinkPickerMode.Content"/>, the URL of the content item will be
        /// retrieved through the content cache (if available). In a similar way, if <see cref="Mode"/> is
        /// <see cref="LinkPickerMode.Media"/> the URL of the media item will be retrieved through the media cache (if
        /// available). The original URL as saved in Umbraco can be accessed through the <see cref="RawUrl"/> property.
        /// </summary>
        [JsonProperty("url")]
        public string Url {
            get { return _url ?? (_url = GetCalculatedUrl()); }
        }

        /// <summary>
        /// Gets the link target.
        /// </summary>
        [JsonProperty("target")]
        public string Target { get; private set; }

        /// <summary>
        /// Gets the mode (or type) of the link.
        /// </summary>
        [JsonProperty("mode")]
        public LinkPickerMode Mode { get; private set; }

        /// <summary>
        /// Gets whether the link is valid.
        /// </summary>
        [JsonIgnore]
        public bool IsValid {
            get { return !String.IsNullOrWhiteSpace(Url); }
        }

        /// <summary>
        /// Gets the raw URL as saved in Umbraco. The URL may be wrong if referencing content or media that has been renamed, moved or similar.
        /// </summary>
        [JsonIgnore]
        public string RawUrl { get; private set; }

        #endregion

        #region Constructors

        internal LinkPickerItem() { }

        /// <summary>
        /// Initializes a new link picker item.
        /// </summary>
        /// <param name="id">The ID of the content or media item.</param>
        /// <param name="name">The name (text) of the link.</param>
        /// <param name="url">The URL of the link.</param>
        /// <param name="target">The target of the link.</param>
        /// <param name="mode">The mode of the link - either <see cref="LinkPickerMode.Content"/>,
        /// <see cref="LinkPickerMode.Media"/> or <see cref="LinkPickerMode.Url"/>.</param>
        public LinkPickerItem(int id, string name, string url, string target, LinkPickerMode mode) {
            Id = id;
            Name = name;
            RawUrl = url;
            Target = target;
            Mode = mode;
        }

        #endregion

        #region Member methods
<commit_msg>Made default LinkPickerItem constructor public so we can make empty instances<commit_after>﻿using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
using Skybrud.LinkPicker.Json.Converters;
using Umbraco.Core.Models;
using Umbraco.Web;

namespace Skybrud.LinkPicker {

    /// <summary>
    /// Class representing a single link item.
    /// </summary>
    [JsonConverter(typeof(LinkPickerConverter))]
    public class LinkPickerItem {

        private string _url;

        #region Properties

        /// <summary>
        /// Gets a reference to the <see cref="JObject"/> the item was parsed from.
        /// </summary>
        [JsonIgnore]
        public JObject JObject { get; private set; }

        /// <summary>
        /// Gets the ID of the selected content or media. If an URL has been selected, this will return <code>0</code>.
        /// </summary>
        [JsonProperty("id")]
        public int Id { get; private set; }

        /// <summary>
        /// Gets the name of the link.
        /// </summary>
        [JsonProperty("name")]
        public string Name { get; private set; }

        /// <summary>
        /// Gets the URL of the link. Since the URL of a content or media item may change over time (eg. if renamed or
        /// moved), this property will attempt to retrieve the current URL from the relevant Umbraco cache.
        /// 
        /// If <see cref="Mode"/> is <see cref="LinkPickerMode.Content"/>, the URL of the content item will be
        /// retrieved through the content cache (if available). In a similar way, if <see cref="Mode"/> is
        /// <see cref="LinkPickerMode.Media"/> the URL of the media item will be retrieved through the media cache (if
        /// available). The original URL as saved in Umbraco can be accessed through the <see cref="RawUrl"/> property.
        /// </summary>
        [JsonProperty("url")]
        public string Url {
            get { return _url ?? (_url = GetCalculatedUrl()); }
        }

        /// <summary>
        /// Gets the link target.
        /// </summary>
        [JsonProperty("target")]
        public string Target { get; private set; }

        /// <summary>
        /// Gets the mode (or type) of the link.
        /// </summary>
        [JsonProperty("mode")]
        public LinkPickerMode Mode { get; private set; }

        /// <summary>
        /// Gets whether the link is valid.
        /// </summary>
        [JsonIgnore]
        public bool IsValid {
            get { return !String.IsNullOrWhiteSpace(Url); }
        }

        /// <summary>
        /// Gets the raw URL as saved in Umbraco. The URL may be wrong if referencing content or media that has been renamed, moved or similar.
        /// </summary>
        [JsonIgnore]
        public string RawUrl { get; private set; }

        #endregion

        #region Constructors
        
        /// <summary>
        /// Initializes an empty link picker item.
        /// </summary>
        public LinkPickerItem() {
            Id = 0;
            Name = string.Empty;
            RawUrl = string.Empty;
            Target = "_self";
            Mode = LinkPickerMode.Url;
        }

        /// <summary>
        /// Initializes a new link picker item.
        /// </summary>
        /// <param name="id">The ID of the content or media item.</param>
        /// <param name="name">The name (text) of the link.</param>
        /// <param name="url">The URL of the link.</param>
        /// <param name="target">The target of the link.</param>
        /// <param name="mode">The mode of the link - either <see cref="LinkPickerMode.Content"/>,
        /// <see cref="LinkPickerMode.Media"/> or <see cref="LinkPickerMode.Url"/>.</param>
        public LinkPickerItem(int id, string name, string url, string target, LinkPickerMode mode) {
            Id = id;
            Name = name;
            RawUrl = url;
            Target = target;
            Mode = mode;
        }

        #endregion

        #region Member methods

{'fraction_non_alphanumeric': 0.12247002707232177, 'fraction_numerical': 0.00038674745391259507, 'mean_word_length': 1.8490635328681602, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5382781', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1998, 'n_words': 760}