using System; using System.Collections.Generic; using System.Net; using InABox.Core; using Newtonsoft.Json; namespace InABox.Clients { public class Credentials { [Obsolete] public string? UserID { get; set; } [Obsolete] public string? Password { get; set; } public string Platform { get; set; } public string Version { get; set; } public Guid Session { get; set; } } public abstract class Request { public Request() { Credentials = new Credentials(); } public static Action? BeforeRequest { get; set; } public Credentials Credentials { get; set; } } public enum StatusCode { OK, Incomplete, Error, Unauthenticated, BadServer } public abstract class Response { public Response() { Status = StatusCode.Incomplete; Messages = new List(); } public StatusCode Status { get; set; } public List Messages { get; } } public abstract class BaseRequest : Request where TEntity : Entity, new() { } public abstract class BaseResponse : Response where TEntity : Entity, new() { } public class ListRequest : BaseRequest where TEntity : Entity, new() { public Filter? Filter { get; set; } public Columns? Columns { get; set; } public SortOrder? Sort { get; set; } } public class ListResponse : BaseResponse where TEntity : Entity, new() { public IEnumerable Data { get; set; } } public class QueryRequest : BaseRequest where TEntity : Entity, new() { public Filter? Filter { get; set; } public Columns? Columns { get; set; } public SortOrder? Sort { get; set; } } public class QueryResponse : BaseResponse where TEntity : Entity, new() { public CoreTable? Items { get; set; } } public class LoadRequest : BaseRequest where TEntity : Entity, new() { public Filter? Filter { get; set; } public SortOrder? Sort { get; set; } } public class LoadResponse : BaseResponse where TEntity : Entity, new() { public TEntity[] Items { get; set; } } public class MultiSaveRequest : BaseRequest where TEntity : Entity, new() { public TEntity[] Items { get; set; } public string AuditNote { get; set; } } public class MultiSaveResponse : BaseResponse where TEntity : Entity, new() { //public Guid[] IDs { get; set; } public TEntity[] Items { get; set; } } public class SaveRequest : BaseRequest where TEntity : Entity, new() { public TEntity Item { get; set; } public string AuditNote { get; set; } } public class SaveResponse : BaseResponse where TEntity : Entity, new() { //public Guid ID { get; set; } public TEntity Item { get; set; } } public class DeleteRequest : BaseRequest where TEntity : Entity, new() { public TEntity Item { get; set; } public string AuditNote { get; set; } } public class DeleteResponse : BaseResponse where TEntity : Entity, new() { } public class MultiDeleteRequest : BaseRequest where TEntity : Entity, new() { public TEntity[] Items { get; set; } public string AuditNote { get; set; } } public class MultiDeleteResponse : BaseResponse where TEntity : Entity, new() { } public class MultiQueryRequest : Request { public Dictionary TableTypes { get; set; } public Dictionary Filters { get; set; } public Dictionary Columns { get; set; } public Dictionary Sorts { get; set; } } public class MultiQueryResponse : Response { public Dictionary Tables { get; set; } } public enum ValidationResult { VALID, INVALID, REQUIRE_2FA, PASSWORD_EXPIRED } public class ValidateRequest : Request { public string? UserID { get; set; } public string? Password { get; set; } public string? PIN { get; set; } public bool UsePIN { get; set; } } public class ValidateResponse : Response { public ValidationResult ValidationResult { get; set; } public Guid UserGuid { get; set; } public string UserID { get; set; } public Guid SecurityID { get; set; } public Guid Session { get; set; } public string? Recipient2FA { get; set; } public DateTime PasswordExpiration { get; set; } } public class Check2FARequest : Request { public string Code { get; set; } } public class Check2FAResponse : Response { public bool Valid { get; set; } } public class PingRequest : Request { } public class PingResponse : Response { } public class InfoRequest : Request { } public class DatabaseInfo { public string? ColorScheme { get; set; } public byte[]? Logo { get; set; } public string Version { get; set; } } public class InfoResponse : Response { public DatabaseInfo Info { get; set; } public InfoResponse() : base() { Info = new DatabaseInfo(); } } public static class Extensions { public static T Status(this T response, StatusCode status) where T : Response { response.Status = status; return response; } } }