import type { MediaReference } from '@core/domain/media/MediaReference';
import type { MediaResolverPort } from '@core/ports/media/MediaResolverPort';
import { Result } from '@core/shared/domain/Result';

export type ResolveMediaReferenceInput = {
  reference: MediaReference;
};

export class ResolveMediaReferenceUseCase {
  constructor(private readonly mediaResolver: MediaResolverPort) {}

  async execute(input: ResolveMediaReferenceInput): Promise<Result<string | null>> {
    try {
      const resolvedPath = await this.mediaResolver.resolve(input.reference);
      return Result.ok(resolvedPath);
    } catch (error) {
      return Result.err(error instanceof Error ? error : new Error(String(error)));
    }
  }
}
