import { Constraint } from '../bson/constraint';
import { DICTIONARY, KnownRecord, RECORD } from "../record";
import { Reference } from '../reference';
import { STRING } from "../string";
import { FieldMap, TypeOf } from './field/field';

export type ModelReference = Reference<Model, "name" | "area">;

export interface Model<T extends {} = KnownRecord> {
  area: string;
  name: string;
  hint: string;
  fields: FieldMap<T>;
  rules: Constraint<T>;
}

export type NamedArgsOf<T> = {
  [P in keyof T]: TypeOf<T[P]>;
};

export const model: Model<Model> = {
  area: "data",
  name: "Model",
  hint: "Object type descriptor",
  fields: {
    area: { type: STRING },
    name: { type: STRING },
    hint: { type: STRING },
    fields: { type: [RECORD, DICTIONARY] },
    rules: { type: [RECORD, DICTIONARY] },
  },
  rules: {},
};
