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 { Router } from '@angular/router';
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 { EmailMessageLogApiService } from '@fleio-api/logger/emai-message-log-api.service';
import { IEmailMessageLogModel } from '@fleio-api/logger/model/email-message-log.model';
import { EmailMessageLogDetailsOverviewComponent } from '@shared/common-tabs/utilities/email-message-log/email-message-log-details-overview/email-message-log-details-overview.component';

export class EmailMessageLogUiService extends ObjectUIServiceBase<IEmailMessageLogModel> {
  private readonly router: Router;
  private readonly config: ConfigService;
  private readonly emailMessageLogApiService: EmailMessageLogApiService;


  constructor(
    emailMessageLogModel: IEmailMessageLogModel, permissions: IPermissionsModel, state: string,
    router: Router, config: ConfigService, emailMessageLogApiService: EmailMessageLogApiService
  ) {
    super(emailMessageLogModel, permissions, state);
    this.router = router;
    this.config = config;
    this.emailMessageLogApiService = emailMessageLogApiService;
  }

  getIcon(): IIcon {
    return null;
  }

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

  getTitle(): ITitle {
    switch (this.state) {
      case 'details':
      default:
        return {
          text: this.object.subject,
          textAsHtml: true,
        };
    }
  }

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

    return actions;
  }

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

    return actions;
  }

  getDetailsLink(): string {
    return this.config.getPanelUrl(`utilities/email-message-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: EmailMessageLogDetailsOverviewComponent,
          },
        ];
        return tabs;
    }
  }

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