import { Injectable, Inject } from '@nestjs/common';
import type { RequestAvatarGenerationInputDTO } from './dtos/RequestAvatarGenerationInputDTO';
import type { RequestAvatarGenerationOutputDTO } from './dtos/RequestAvatarGenerationOutputDTO';

type RequestAvatarGenerationInput = RequestAvatarGenerationInputDTO;
type RequestAvatarGenerationOutput = RequestAvatarGenerationOutputDTO;

// Use cases
import { RequestAvatarGenerationUseCase } from '@core/media/application/use-cases/RequestAvatarGenerationUseCase';

// Presenters
import { RequestAvatarGenerationPresenter } from './presenters/RequestAvatarGenerationPresenter';

// Tokens
import { REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN, LOGGER_TOKEN } from './MediaProviders';
import type { Logger } from '@core/shared/application';

@Injectable()
export class MediaService {
  constructor(
    @Inject(REQUEST_AVATAR_GENERATION_USE_CASE_TOKEN) private readonly requestAvatarGenerationUseCase: RequestAvatarGenerationUseCase,
    @Inject(LOGGER_TOKEN) private readonly logger: Logger,
  ) {}

  async requestAvatarGeneration(input: RequestAvatarGenerationInput): Promise<RequestAvatarGenerationOutput> {
    this.logger.debug('[MediaService] Requesting avatar generation.');

    const presenter = new RequestAvatarGenerationPresenter();
    await this.requestAvatarGenerationUseCase.execute({
      userId: input.userId,
      facePhotoData: input.facePhotoData,
      suitColor: input.suitColor as any,
    }, presenter);
    return presenter.viewModel;
  }
}
