using System.Collections.Generic;
using System.Linq;
namespace StardewModdingAPI.Web.ViewModels.JsonValidator
{
/// The view model for the JSON validator page.
public class JsonValidatorModel
{
/*********
** Accessors
*********/
/// The root URL for the log parser controller.
public string SectionUrl { get; set; }
/// The paste ID.
public string PasteID { get; set; }
/// The schema name with which the JSON was validated.
public string SchemaName { get; set; }
/// The supported JSON schemas (names indexed by ID).
public readonly IDictionary SchemaFormats;
/// The validated content.
public string Content { get; set; }
/// The schema validation errors, if any.
public JsonValidatorErrorModel[] Errors { get; set; } = new JsonValidatorErrorModel[0];
/// An error which occurred while uploading the JSON to Pastebin.
public string UploadError { get; set; }
/// An error which occurred while parsing the JSON.
public string ParseError { get; set; }
/// A web URL to the user-facing format documentation.
public string FormatUrl { get; set; }
/*********
** Public methods
*********/
/// Construct an instance.
public JsonValidatorModel() { }
/// Construct an instance.
/// The root URL for the log parser controller.
/// The paste ID.
/// The schema name with which the JSON was validated.
/// The supported JSON schemas (names indexed by ID).
public JsonValidatorModel(string sectionUrl, string pasteID, string schemaName, IDictionary schemaFormats)
{
this.SectionUrl = sectionUrl;
this.PasteID = pasteID;
this.SchemaName = schemaName;
this.SchemaFormats = schemaFormats;
}
/// Set the validated content.
/// The validated content.
public JsonValidatorModel SetContent(string content)
{
this.Content = content;
return this;
}
/// Set the error which occurred while uploading the log to Pastebin.
/// The error message.
public JsonValidatorModel SetUploadError(string error)
{
this.UploadError = error;
return this;
}
/// Set the error which occurred while parsing the JSON.
/// The error message.
public JsonValidatorModel SetParseError(string error)
{
this.ParseError = error;
return this;
}
/// Add validation errors to the response.
/// The schema validation errors.
public JsonValidatorModel AddErrors(params JsonValidatorErrorModel[] errors)
{
this.Errors = this.Errors.Concat(errors).ToArray();
return this;
}
}
}