using Newtonsoft.Json;
using RuriLib.ViewModels;
using System.Collections.Generic;
using System.Linq;
using RuriLib.LS;
using System.Text.RegularExpressions;
using System;
namespace RuriLib
{
///
/// Represents a configuration in RuriLib.
///
public class Config : ViewModelBase
{
///
/// Creates a Config given the settings and the script.
///
/// The settings of the Config
/// The LoliScript script of the Config
public Config(ConfigSettings settings, string script)
{
Settings = settings;
Script = script;
}
/// The settings of the Config.
public ConfigSettings Settings { get; set; }
/// The LoliScript script of the Config.
public string Script { get; set; }
/// Whether Selenium is being used in any of the blocks of the Config.
public bool SeleniumPresent { get { return Script.Contains("NAVIGATE") || Script.Contains("BROWSERACTION") || Script.Contains("ELEMENTACTION") || Script.Contains("EXECUTEJS") || Script.Contains("MOUSEACTION"); } }
/// Whether a possibly dangerous JavaScript or IronPython script is present in the Config.
public bool DangerousScriptPresent { get { return Script.ToUpper().Contains("BEGIN SCRIPT"); } }
/// Whether captcha solving blocks are present in the Config.
public bool CaptchasNeeded { get { return Script.Contains("CAPTCHA"); } }
/// Whether bypasscf blocks are present in the Config.
public bool HasCFBypass { get { return Script.Contains("BYPASSCF"); } }
/// The amount of blocks of the Config.
public int BlocksAmount { get { return Script.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Where(l => BlockParser.IsBlock(l)).Count(); } }
/// The joined representation of the allowed WordlistTypes.
public string AllowedWordlists { get { return $"{Settings.AllowedWordlist1} | {Settings.AllowedWordlist2}"; } }
/// The pretty representation of the time when the Config was last modified.
public string LastModifiedString { get { return $"{Settings.LastModified.ToShortDateString()} {Settings.LastModified.ToShortTimeString()}"; } }
}
}