import {Component, Input} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {NgForOf, NgIf} from "@angular/common";
import {QueryComponent} from "../query/query.component";
import {SchemaField} from "../../../app/search/search.component";

export type FieldType = 'number' | 'string' | 'flag' | 'grade' | 'boolean' | 'datetime' | 'playtime';
export type OperatorType = '=' | '>' | '<' | 'contains' | 'like' | '>=' | '<=' | '!=';
export type ValueType = 'any' | 'boolean' | 'flag' | 'grade' | 'datetime';

export interface Predicate {
  field: SchemaField | null;
  operator: Operator | null;
  value: string | number | null;
}

export interface Operator {
  operatorType: OperatorType;
  acceptsValues: ValueType;
}

export interface Query {
  predicates: Predicate[];
  logicalOperator: 'AND' | 'OR';
  childQueries?: Query[];
}

@Component({
  selector: 'app-query-builder',
  standalone: true,
  imports: [
    FormsModule,
    NgForOf,
    NgIf,
    QueryComponent
  ],
  templateUrl: './query-builder.component.html',
  styleUrl: './query-builder.component.css'
})
export class QueryBuilderComponent {

  @Input() queries: Query[] = [];
  @Input() fields: SchemaField[] = [];

  addQuery(): void {
    this.queries.push({
      predicates: [],
      logicalOperator: 'AND'
    });
  }

  removeQuery(queryIndex: number): void {
    this.queries.splice(queryIndex, 1);
  }

  queryChanged(): void {

  }

}
