package com.javarush.task.task19.task1904;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
И еще один адаптер
*/

public class Solution {

    public static void main(String[] args) throws IOException {
        Scanner p = new Scanner(new FileReader("C:/Java/1.txt"));
        PersonScannerAdapter test = new PersonScannerAdapter(p);
        Person tp = test.read();
        System.out.println(tp.toString());

    }

    public static class PersonScannerAdapter implements PersonScanner{
    private final Scanner fileScanner;
        PersonScannerAdapter (Scanner inscan) throws FileNotFoundException {
            this.fileScanner = inscan;
        }
        @Override
        public Person read() throws IOException {
            Person ps1 = null;
            if (fileScanner.hasNext()) {
                String s = fileScanner.nextLine();
                String[] ar = new String[5];
                ar = s.split(" ");
                String firstName = ar[0].toString();
                String middleName = ar[2].toString();
                String lastName = ar[1].toString();
                Calendar calendar = new GregorianCalendar(Integer.parseInt(ar[5]),Integer.parseInt(ar[4])-1,Integer.parseInt(ar[3]));
                Date date = calendar.getTime();
                ps1 = new Person(firstName,middleName,lastName,date);
            }
            return ps1;
        }

        @Override
        public void close() throws IOException {
            fileScanner.close();
        }
    }
}