import { CoreModel, mapClasses, Restricted, RoleEnum } from '@lenne.tech/nest-server';
import { Field, ObjectType } from '@nestjs/graphql';
import { Schema as MongooseSchema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema } from 'mongoose';<%- props.imports %>

import { User } from '../../../modules/user/user.model';

export type <%= props.namePascal %>Document = <%= props.namePascal %> & Document;

/**
 * <%= props.namePascal %> model
 */
@Restricted(RoleEnum.ADMIN)
@ObjectType({ description: '<%= props.namePascal %>' })
@MongooseSchema({ _id: false })
export class <%= props.namePascal %> extends CoreModel {

  // ===================================================================================================================
  // Properties
  // ===================================================================================================================
  <%- props.props %>

  // ===================================================================================================================
  // Methods
  // ===================================================================================================================

  /**
   * Initialize instance with default values instead of undefined
   */
  override init() {
    super.init();
    // this.xxx = [];
    return this;
  }

  /**
   * Map input
   *
   * Hint: Non-primitive variables should always be mapped (see mapClasses / mapClassesAsync in ModelHelper)
   */
  override map(input) {
    super.map(input);
    return <%- props.mappings %>
  }

  /**
   * Verification of the user's rights to access the properties of this object
   */
  override securityCheck(user: User, force?: boolean) {
    if (force || user?.hasRole(RoleEnum.ADMIN)) {
      return this;
    }
    // Check rights for properties of this object
    return this;
  }
}

export const <%= props.namePascal %>Schema = SchemaFactory.createForClass(<%= props.namePascal %>);
