// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.Linq; using Squidex.Infrastructure; using Squidex.Infrastructure.Json.Objects; using Squidex.Infrastructure.Queries; namespace Squidex.Domain.Apps.Entities { public sealed class Q : Cloneable { public static readonly Q Empty = new Q(); public IReadOnlyList Ids { get; private set; } public Guid? Reference { get; private set; } public string? ODataQuery { get; private set; } public string? JsonQuery { get; private set; } public Query? ParsedJsonQuery { get; private set; } public ClrQuery? Query { get; private set; } public Q WithQuery(ClrQuery? query) { return Clone(c => c.Query = query); } public Q WithODataQuery(string? odataQuery) { return Clone(c => c.ODataQuery = odataQuery); } public Q WithJsonQuery(string? jsonQuery) { return Clone(c => c.JsonQuery = jsonQuery); } public Q WithJsonQuery(Query? jsonQuery) { return Clone(c => c.ParsedJsonQuery = jsonQuery); } public Q WithIds(params Guid[] ids) { return Clone(c => c.Ids = ids.ToList()); } public Q WithReference(Guid? reference) { return Clone(c => c.Reference = reference); } public Q WithIds(IEnumerable ids) { return Clone(c => c.Ids = ids.ToList()); } public Q WithIds(string? ids) { if (!string.IsNullOrEmpty(ids)) { return Clone(c => { var idsList = new List(); foreach (var id in ids.Split(',')) { if (Guid.TryParse(id, out var guid)) { idsList.Add(guid); } } c.Ids = idsList; }); } return this; } } }