import { IContext, IParam, EntityService } from '@core';

/**
 * {{appEntity.logicName}}服务对象基类
 *
 * @export
 * @class {{pascalCase appEntity.codeName}}
 * @extends {EntityBaseService}
 */
export class {{pascalCase appEntity.codeName}}ServiceBase extends EntityService {
  
  /**
  * Creates an instance of {{pascalCase appEntity.codeName}}ServiceBase.
  *
  * @param {*} [opts={}]
  * @memberof {{pascalCase appEntity.codeName}}ServiceBase
  */
  constructor(opts: IParam = {}) {
    super(opts,'{{pascalCase appEntity.codeName}}');
  }

  /**
   * 初始化基础数据
   *
   * @protected
   * @memberof ChartDataServiceBase
   */
  protected initBasicData() {
    this.appEntityCodeName = '{{lowerCase appEntity.codeName}}';
    this.appEntityCodeNames = '{{pluralize appEntity.codeName}}';
    {{#if appEntity.keyPSAppDEField}}
    this.appEntityKeyCodeName = '{{lowerCase appEntity.keyPSAppDEField.codeName}}';
    {{/if}}
    {{#if appEntity.majorPSAppDEField}}
    this.appEntityTextCodeName = '{{lowerCase appEntity.majorPSAppDEField.codeName}}';
    {{/if}}
    // 初始化关系实体路径集合
    this.deResPaths = [
      {{#each appEntity.appEntityResources as |appEntityResource| }}
      {{appEntityResource.deResPaths}}{{#unless @last}},{{/unless}}
      {{/each}}
    ]
  }

{{#each appEntity.allPSAppDEMethods as |singleAppMethod| }}
  {{! 非内置行为和非临时数据方法才输出 }}
  {{#if (and (eq builtinMethod false) (eq tempDataMode 0))}}
    {{#if (eq appEntity.psDEServiceAPI.nested true)}}
      {{#or (eq methodType 'FETCH') (eq methodType 'SELECT')}}
  {{> @macro/front-end/entity/service-nested-fetch-method.hbs singleAppMethod=singleAppMethod}}

      {{/or}}
    {{!-- todo嵌套行为补充 --}}
    {{else}}
    {{!-- todo 插件 --}}
      {{#if (and (eq methodType 'DEACTION') psDEAction (eq psDEAction.actionType 'DELOGIC'))}}
      {{!-- 实体处理逻辑 --}}
  {{> @macro/front-end/entity/service-delogic-method.hbs singleAppMethod=singleAppMethod}}

      {{else if (and (eq methodType 'DEACTION') psDEAction (eq psDEAction.actionType 'SCRIPT'))}}
      {{!-- 脚本代码 --}}
  {{> @macro/front-end/entity/service-script-method.hbs singleAppMethod=singleAppMethod}}

      {{else if (and singleAppMethod.psDEServiceAPIMethod (or appEntity.major appEntity.minorPSAppDERSs))}}
      {{!-- 远程接口 --}}
  {{> @macro/front-end/entity/service-remote-method.hbs singleAppMethod=singleAppMethod}}

      {{/if}}
    {{/if}}
  {{/if}}
{{/each}}
}