# W tym pliku mamy definicję klasy Employee - obiekt tej klasy reprezentuje jednego pracownika i zawiera jego dane.
# Mamy też funkcje odpowiedzialne za odczyt i zapis danych z/do pliku csv.

class Employee:
    def __init__(self, employee_id, first_name, last_name, job_title, salary, hire_date, department_name, address, postal_code, city, country):
        self.employee_id = employee_id
        self.first_name = first_name
        self.last_name = last_name
        self.job_title = job_title
        self.salary = salary
        self.hire_date = hire_date
        self.department_name = department_name
        self.address = address
        self.postal_code = postal_code
        self.city = city
        self.country = country


    def __str__(self):
        return f'Pracownik nr {self.employee_id}: {self.first_name} {self.last_name} ({self.job_title}), pensja {self.salary}'


def read_csv(file_path='emps.csv'):
    emps = []
    with open(file_path, mode='r', encoding='utf-8') as file:
        file.readline()
        for line in file:
            t = line.strip().split(';')
            emp = Employee(int(t[0]), t[1], t[2], t[3], int(t[4]),
                           t[5], t[6], t[7], t[8], t[9], t[10])
            emps.append(emp)
    return emps


def write_csv(emps, sciezka):
    with open(sciezka, mode='w', encoding='utf-8') as plik:
        plik.write('employee_id;first_name;last_name;job_title;salary;hire_date;department_name;address;postal_code;city;country\n')
        for emp in emps:
            print(emp.employee_id, emp.first_name, emp.last_name, emp.job_title, emp.salary,
                  emp.hire_date, emp.department_name, emp.address, emp.postal_code, emp.city, emp.country,
                  sep=';', file=plik)
