# worker-1/main.py
import os


def find_file_with_most_lines(directory):
    files = os.listdir(directory)
    max_lines = 0
    target_file = None
    for filename in files:
        filepath = os.path.join(directory, filename)
        if os.path.isfile(filepath):
            with open(filepath, 'r') as file:
                lines = file.readlines()
                if len(lines) > max_lines:
                    max_lines = len(lines)
                    target_file = filepath
    return target_file


def main():
    source_directory = '/var/data'
    result_file = '/var/result/data.txt'

    file_to_copy = find_file_with_most_lines(source_directory)

    if file_to_copy:
        with open(file_to_copy, 'r') as source, open(result_file, 'w') as dest:
            dest.writelines(source.readlines())
        print(f"File with the most lines: {file_to_copy} copied to {result_file}")
    else:
        print("No files found in the source directory.")


if __name__ == "__main__":
    main()