/**
 * MediaService
 *
 * Frontend orchestration service for media operations.
 * Handles binary media fetching with proper error handling.
 */

import { Result } from '@/lib/contracts/Result';
import { Service, DomainError } from '@/lib/contracts/services/Service';
import { MediaAdapter } from '@/lib/adapters/MediaAdapter';
import { MediaBinaryDTO } from '@/lib/types/MediaBinaryDTO';

/**
 * MediaService
 *
 * Handles media asset fetching with proper error handling.
 * Creates its own dependencies and orchestrates adapter calls.
 */
export class MediaService implements Service {
  private adapter: MediaAdapter;

  constructor() {
    // Service creates its own dependencies
    this.adapter = new MediaAdapter();
  }

  /**
   * Get avatar for a driver
   */
  async getAvatar(driverId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/avatar/${driverId}`);
  }

  /**
   * Get category icon
   */
  async getCategoryIcon(categoryId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/categories/${categoryId}/icon`);
  }

  /**
   * Get league cover
   */
  async getLeagueCover(leagueId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/leagues/${leagueId}/cover`);
  }

  /**
   * Get league logo
   */
  async getLeagueLogo(leagueId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/leagues/${leagueId}/logo`);
  }

  /**
   * Get sponsor logo
   */
  async getSponsorLogo(sponsorId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/sponsors/${sponsorId}/logo`);
  }

  /**
   * Get team logo
   */
  async getTeamLogo(teamId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/teams/${teamId}/logo`);
  }

  /**
   * Get track image
   */
  async getTrackImage(trackId: string): Promise<Result<MediaBinaryDTO, DomainError>> {
    return this.adapter.fetchMedia(`/media/tracks/${trackId}/image`);
  }
}