import { Injectable } from '@nestjs/common';
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
import { ItemQueueEntity } from '../../entities/item-queue.entity';
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';

@Injectable()
export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
  async prepareData(): Promise<void> {
    return;
  }

  async beforeProcess(): Promise<void> {
    return;
  }

  async afterProcess(): Promise<void> {
    return;
  }

  get relations(): RelationParam {
    return {
      joinRelations: [],
      selectRelations: ['items', 'items.time_group'],
      countRelations: [],
    };
  }

  get selects(): string[] {
    return [
      `${this.tableName}.id`,
      `${this.tableName}.status`,
      `${this.tableName}.name`,
      `${this.tableName}.information`,
      `${this.tableName}.item_type`,
      `${this.tableName}.created_at`,
      `${this.tableName}.creator_name`,
      `${this.tableName}.updated_at`,
      `${this.tableName}.editor_name`,
      `${this.tableName}.max_peak_level`,
      `${this.tableName}.call_preparation`,
      `${this.tableName}.use_notification`,
      `${this.tableName}.requiring_notification`,
      `${this.tableName}.usage_type`,

      `items.id`,
      `items.created_at`,
      `items.status`,
      `items.item_type`,
      `items.name`,
      `items.hpp`,
      `items.limit_type`,
      `items.limit_value`,
      `items.base_price`,
      `items.share_profit`,
      `items.play_estimation`,
      `items.video_url`,

      'time_group.id',
      'time_group.name',
    ];
  }

  get setFindProperties(): any {
    return {
      id: this.dataId,
    };
  }

  getResult(): ItemQueueEntity {
    const videos = this.result.items.map((item) => {
      return item.video_url ?? [];
    });
    this.result['videos'] = videos.flat();
    return this.result;
  }
}
