import Image from '../docker/image.js';
import ImageAccessDetailsRetriever from './imageAccessDetailsRetriever.js';
export default class ImagePuller {
    docker;
    imageName;
    constructor(docker, imageName) {
        this.docker = docker;
        this.imageName = imageName;
    }
    async pull() {
        const imageAccessDetailsRetriever = new ImageAccessDetailsRetriever(this.imageName);
        let finalError;
        for (const force of [false, true]) {
            // eslint-disable-next-line no-await-in-loop
            const { imageUrl, password, username } = await imageAccessDetailsRetriever.get(force);
            try {
                const image = new Image(this.docker, imageUrl);
                // eslint-disable-next-line no-await-in-loop
                await image.pull(imageUrl, username, password);
                return image;
            }
            catch (error) {
                finalError = error;
            }
        }
        throw finalError;
    }
}
