# -*- coding: utf-8 -*-
# Author: Greg He

import os
import re


class SyncRequest(object):
    def __init__(self):
        self.file_name = ""
        self.from_path = ""
        self.to_path = ""
        self.is_valid = False

    def __process_path(self):
        if self.from_path.endswith("\\"):
            self.from_path = self.from_path[:-1]
        if self.to_path.endswith("\\"):
            self.to_path = self.to_path[:-1]

        self.from_path = self.from_path.strip()
        self.to_path = self.to_path.strip()

    def validation(self):
        self.__process_path()

        result = True

        pattern = re.compile(r"\S+UX\d+", re.I)
        if not pattern.match(self.to_path):
            result = False

        if not os.path.exists(self.from_path):
            result = False

        if not os.path.exists(self.to_path):
            result = False

        self.is_valid = result
        return result

    def __str__(self):
        return "robocopy \"%s\" \"%s\" /S /XO /MT:20 /XA:H" % (self.from_path, self.to_path)
