using System;
using System.Collections.Generic;
using System.Linq;
namespace StardewModdingAPI.Web.ViewModels.JsonValidator
{
/// The view model for the JSON validator page.
public class JsonValidatorModel
{
/*********
** Accessors
*********/
/// Whether to show the edit view.
public bool IsEditView { 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];
/// A non-blocking warning while uploading the file.
public string UploadWarning { get; set; }
/// When the uploaded file will no longer be available.
public DateTime? Expiry { get; set; }
/// An error which occurred while uploading the JSON.
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 stored file ID.
/// The schema name with which the JSON was validated.
/// The supported JSON schemas (names indexed by ID).
/// Whether to show the edit view.
public JsonValidatorModel(string pasteID, string schemaName, IDictionary schemaFormats, bool isEditView)
{
this.PasteID = pasteID;
this.SchemaName = schemaName;
this.SchemaFormats = schemaFormats;
this.IsEditView = isEditView;
}
/// Set the validated content.
/// The validated content.
/// When the uploaded file will no longer be available.
/// A non-blocking warning while uploading the log.
public JsonValidatorModel SetContent(string content, DateTime? expiry, string uploadWarning = null)
{
this.Content = content;
this.Expiry = expiry;
this.UploadWarning = uploadWarning;
return this;
}
/// Set the error which occurred while uploading the JSON.
/// 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;
}
}
}