package com.jscape.filetransfer;

import com.jscape.util.Parameters;
import com.jscape.util.SuppressObfuscation;

import java.util.List;

/**
 * @author Alex Usun
 */
@SuppressObfuscation
public interface RemoteDirectory
        extends FileTransferOperation {

    @SuppressObfuscation
    class CurrentDirectory
            implements RemoteDirectory {

        @Override
        public FileTransferOperation applyTo(FileTransfer transfer)
                throws FileTransferException {
            return this;
        }
    }

    @SuppressObfuscation
    class PathDirectory
            implements RemoteDirectory {

        private final String path;

        public PathDirectory(String path) {
            this.path = path;
        }

        @Override
        public FileTransferOperation applyTo(FileTransfer transfer)
                throws FileTransferException {
            transfer.setDir(this.path);
            return this;
        }

        @Override
        public String toString() {
            return "PathDirectory {"
                    + "path='" + this.path + '\''
                    + '}';
        }
    }

    @SuppressObfuscation
    class PathElementsDirectory
            implements RemoteDirectory {

        private final List<String> pathElements;

        public PathElementsDirectory(List<String> pathElements) {
            Parameters.assertNotNull(pathElements);
            this.pathElements = pathElements;
        }

        @Override
        public FileTransferOperation applyTo(FileTransfer transfer)
                throws FileTransferException {
            for (String element : this.pathElements) {
                transfer.setDir(element);
            }

            return this;
        }

        @Override
        public String toString() {
            return "PathElementsDirectory {"
                    + "pathElements=" + this.pathElements
                    + '}';
        }
    }
}
