import { IPermissionsModel } from '@fleio-api/base-model/IPermissionsModel';
import { IIcon } from '@shared/ui/common/interfaces/icon';
import { ITitle } from '@objects-view/interfaces/card-data/card-title';
import { IObjectStatus, StatusType, StatusValue } from '@objects-view/interfaces/object-status';
import { ObjectUIServiceBase } from '@objects-view/object-ui-service-base';
import { IAction } from '@objects-view/interfaces/actions/action';
import { ConfigService } from '@shared/config/config.service';
import { IDataField } from '@objects-view/interfaces/card-data/data-field';
import { IDetailsTab } from '@objects-view/interfaces/details/details-tab';
import { IPeriodicTaskLogModel } from '@fleio-api/logger/model/periodic-task-log.model';
import { PeriodicTaskLogDetailsOverviewComponent } from './tabs/periodic-task-log-details-overview/periodic-task-log-details-overview.component';
import { PeriodicTaskLogDetailsLogfileComponent } from './tabs/periodic-task-log-details-logfile/periodic-task-log-details-logfile.component';
import {
  PeriodicTaskLogDetailsEmailsComponent
} from './tabs/periodic-task-log-details-emails/periodic-task-log-details-emails.component';
import {
  PeriodicTaskLogDetailsTasksComponent
} from './tabs/periodic-task-log-details-tasks/periodic-task-log-details-tasks.component';
import { DateFormatterPipe } from '@shared/ui/common/pipes/date-formatter.pipe';

export class PeriodicTaskLogUiService extends ObjectUIServiceBase<IPeriodicTaskLogModel> {
  private readonly config: ConfigService;
  private readonly datePipe: DateFormatterPipe;


  constructor(
    periodicTaskLog: IPeriodicTaskLogModel, permissions: IPermissionsModel, state: string,
    config: ConfigService,
  ) {
    super(periodicTaskLog, permissions, state);
    this.config = config;
    this.datePipe = new DateFormatterPipe(this.config);
  }

  getIcon(): IIcon {
    return null;
  }

  getStatus(): IObjectStatus {
    switch (this.object.status) {
      case 'running':
        return {
          type: StatusType.Defined,
          value: StatusValue.Started,
        };
      case 'success':
        return {
          type: StatusType.Defined,
          value: StatusValue.Success,
        };
      case 'error':
        return {
          type: StatusType.Defined,
          value: StatusValue.Error,
        };
      case 'timeout':
        return {
          type: StatusType.Defined,
          value: StatusValue.Warning,
        };
      default:
        return null;
    }
  }

  getTitle(): ITitle {
    switch (this.state) {
      case 'details':
      default:
        return {
          text: $localize`Task "${this.object.task_name}" on ${this.datePipe.transform(this.object.start_dt)}`,
        };
    }
  }

  getActions(): IAction[] {
    const actions: IAction[] = [];

    return actions;
  }

  getDetailsActions(): IAction[] {
    const actions = [];

    return actions;
  }

  getDetailsLink(): string {
    return this.config.getPanelUrl(`utilities/periodic-task-log/${this.object.id}`);
  }

  getCardFields(): IDataField[] {
    const fields = [];

    return fields;
  }

  getTabs(): IDetailsTab[] {
    switch (this.state) {
      case 'details':
        const tabs: IDetailsTab[] = [
          {
            tabName: $localize`Overview`,
            tabIdentifier: 'overview',
            component: PeriodicTaskLogDetailsOverviewComponent,
          },
{
            tabName: $localize`Tasks`,
            tabIdentifier: 'tasks',
            component: PeriodicTaskLogDetailsTasksComponent,
          },{
            tabName: $localize`Log file`,
            tabIdentifier: 'log-file',
            component: PeriodicTaskLogDetailsLogfileComponent,
          },{
          tabName: $localize`Email log`,
          tabIdentifier: 'email-log',
          component: PeriodicTaskLogDetailsEmailsComponent,
          featureName: 'logger.email-message-log',
        }];

        return tabs;
    }
  }

  getCardTags(): string[] {
    const tags: string[] = [];
    return tags;
  }
}
