﻿using System;

namespace Carbon.Data.Expressions
{
    public class Query
    {
        public Query(Expression expression)
        {
            Expression = expression;
        }

        public Query(string indexName, Expression expression)
        {
            Index = new QueryIndex(indexName);
            Expression = expression;
        }
       
        public Query(Expression expression, params Order[] orders)
        {
            Expression = expression;
            Orders = orders;

        }
        public Expression Expression { get; }

        public Order[] Orders { get; }

        public int Skip { get; set; }

        public int? Take { get; set; }

        public QueryIndex? Index { get; set; }
    }

    public readonly struct QueryIndex
    {
        public QueryIndex(string name, SortDirection? direction = null)
        {
            Name      = name ?? throw new ArgumentNullException(nameof(name));
            Direction = direction;
        }

        public string Name { get; }
         
        public SortDirection? Direction { get; }
    }
}
