// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_crud_bloc/src/core/enums/where_query_type.dart';

// // ignore: one_member_abstracts
// abstract class QueryParser<Q> {
//   Q parser(QueryInterface condition, Q query);
// }

typedef QueryParser<Q> = Q Function(QueryInterface condition, Q query);

/// {@template query}
/// An abstract class that represents a query.
/// {@endtemplate}
abstract class QueryInterface extends Entity {
  /// {@macro query}
  const QueryInterface();
}

/// {@template where_query}
/// Represents a where query.
/// {@endtemplate}
class WhereQuery<Value> extends QueryInterface {
  /// {@macro where_query}
  const WhereQuery(this.type, this.field, this.value);

  /// The type of the where query.
  final WhereQueryType type;

  /// The field of the where query.
  final String field;

  /// The value of the where query.
  final Value value;
}

/// {@template limit_query}
/// Represents a limit query.
/// {@endtemplate}
class LimitQuery extends QueryInterface {
  /// {@macro limit_query}
  const LimitQuery(this.limit);

  /// The limit of the limit query.
  final int limit;
}

/// {@template offset_query}
/// Represents an offset query.
/// {@endtemplate}
class OrderByQuery extends QueryInterface {
  /// {@macro offset_query}
  const OrderByQuery(this.field, {this.ascending = true});

  /// The field of the order by query.
  final String field;

  /// The ascending of the order by query.
  final bool ascending;
}
