from geneator import Geneator
import random
import string
import re

class Passport(Geneator):
    """
    참고자료: https://www.passport.go.kr/new/board/story.php?idx=187&sel=1
    """
    def __init__(self):
        self.re = "^([MSRGDmsrgd][0-9]{8}|[a-zA-Z]{2}[0-9]{7})$"
        self.filename = ""

    def save(self):
        """
        저장
        """
        pass

    def check(self):
        """ㄴ
        유효성검사 없음
        """
        pass

    def extract(self, data):
        """
        추출
        """
        _regex = re.compile(self.re)
        _t = _regex.search(data)

        if _t:
            return _t.group()

        return ""

    def create(self):
        """
        여권번호 생성
        알파벳 1 + 8개의 숫자 또는
        알파벳 2 + 7개의 숫자
        """
        result = ""
        _seed = ['M', 'S', 'R', 'G', 'D', 'TC']
        digit_seed = 8

        result += random.choice(_seed)
        if len(result) == 2:
            digit_seed = 7

        for idx in range(0, digit_seed):
            result += random.choice(string.digits)
        
        return result
        