<?php

namespace Lucent\Query;


final class Operator
{
    /**
     * @psalm-param string[] $uis
     */
    public function __construct(
        public string $name,
        public string $label,
        public string $symbol,
        public string $db,
        public array  $uis,
    )
    {
    }

    /**
     * @return  array<string, Operator>
     */
    public static function list(): array
    {

        return [
            "regex" => new Operator(
                name: "regex",
                label: "Search",
                symbol: "~",
                db: 'like',
                uis: ["id", "text", "textarea", "url", "color", "date", "datetime"],
            ),
            "eq" => new Operator(
                name: "eq",
                label: "Equals",
                symbol: "is",
                db: '=',
                uis: ["id", "text", "textarea", "url", "color", "date", "datetime", "reference"],
            ),
            "ne" => new Operator(
                name: "ne",
                label: "Not Equals",
                symbol: "is not",
                db: '!=',
                uis: ["id", "text", "textarea", "url", "color", "date", "datetime"],
            ),
            "eqnum" => new Operator(
                name: "eqnum",
                label: "Equals number",
                symbol: "is",
                db: '=',
                uis: ["number"],
            ),
            "neqnum" => new Operator(
                name: "nenum",
                label: "Not Equals number",
                symbol: "is not",
                db: '$ne',
                uis: ["number"],
            ),
            "filter" => new Operator(
                name: "filter",
                label: "Equals Object",
                symbol: "is",
                db: 'filter',
                uis: [],
            ),
            "eqtrue" => new Operator(
                name: "eqtrue",
                label: "Equals true",
                symbol: "is",
                db: '=',
                uis: ["checkbox"],
            ),
            "eqfalse" => new Operator(
                name: "eqfalse",
                label: "Equals false",
                symbol: "is not",
                db: '=',
                uis: ["checkbox"],
            ),
            "netrue" => new Operator(
                name: "netrue",
                label: "Not equals true",
                symbol: "!=",
                db: '$ne',
                uis: ["checkbox"],
            ),
            "nefalse" => new Operator(
                name: "nefalse",
                label: "Not equals false",
                symbol: "!=",
                db: '$ne',
                uis: ["checkbox"],
            ),
            "in" => new Operator(
                name: "in",
                label: "In list",
                symbol: "in",
                db: 'in',
                uis: ["id", "text", "textarea", "url", "color", "date", "datetime"],
            ),
            "innum" => new Operator(
                name: "innum",
                label: "In list of numbers",
                symbol: "in",
                db: '$in',
                uis: ["number"],
            ),
            "nin" => new Operator(
                name: "nin",
                label: "Not in list",
                symbol: "not in",
                db: 'nin',
                uis: ["id", "text", "textarea", "url", "color", "date", "datetime"],
            ),
            "ninnum" => new Operator(
                name: "ninnum",
                label: "Not In list of numbers",
                symbol: "not in",
                db: '$nin',
                uis: ["number"],
            ),
            "lt" => new Operator(
                name: "lt",
                label: "Less than",
                symbol: "<",
                db: '<',
                uis: ["number", "date", "datetime"],
            ),
            "lte" => new Operator(
                name: "lte",
                label: "Less than equals",
                symbol: "<=",
                db: '<=',
                uis: ["number", "date", "datetime"],
            ),
            "gt" => new Operator(
                name: "gt",
                label: "Greater than",
                symbol: ">",
                db: '>',
                uis: ["number", "date", "datetime"],
            ),
            "gte" => new Operator(
                name: "gte",
                label: "Greater than equals",
                symbol: ">=",
                db: '>=',
                uis: ["number", "date", "datetime"],
            ),
            "null" => new Operator(
                name: "null",
                label: "Is null",
                symbol: "=",
                db: '$eq',
                uis: ["*"],
            ),
            "nnull" => new Operator(
                name: "nnull",
                label: "Not null",
                symbol: "!=",
                db: '$ne',
                uis: ["*"],
            ),
            "exists" => new Operator(
                name: "exists",
                label: "Exists",
                symbol: "exists",
                db: 'exists',
                uis: ["*"],
            ),
            "nexists" => new Operator(
                name: "nexists",
                label: "Not exists",
                symbol: "not exists",
                db: '$exists',
                uis: ["*"],
            ),


        ];
    }
}
