#include <string>
#include <ctime>
#include "triedy.h"
using namespace std;

rodne_cislo::rodne_cislo(char *r)
{
	strcpy(rc, r);
	pohlavie = vrat_pohlavie();
}

char *rodne_cislo::vrat_rc()
{
	char *pom;
	pom = new char[12];
	strcpy(pom, rc);
	return pom;
}

int rodne_cislo::vrat_den()
{
	char pom[3];
	pom[0] = rc[4];
	pom[1] = rc[5];
	pom[2] = '\0';
	return (atoi(pom));
}

int rodne_cislo::vrat_mesiac()
{
	char pom[3];
	pom[0] = rc[2];
	pom[1] = rc[3];
	pom[2] = '\0';
	return (vrat_pohlavie() == 0) ? (atoi(pom) - 50) : atoi(pom);
}

int rodne_cislo::vrat_rok()
{
	char pom[3];
	int int_pom;
	pom[0] = rc[0];
	pom[1] = rc[1];
	pom[2] = '\0';
	int_pom = atoi(pom);
	if (int_pom < 15)
		return int_pom + 2000;	//2000 - 2014
	else
		return int_pom + 1900;	//1915 - 1999
}

int rodne_cislo::vrat_pohlavie()
{
	char pom[3];
	pom[0] = rc[2];
	pom[1] = rc[3];
	pom[2] = '\0';
	return (atoi(pom)>50) ? 0 : 1;
}

void rodne_cislo::nastav_rc(char *r)
{
	strcpy(rc, r);
	pohlavie = vrat_pohlavie();
}

int rodne_cislo::vrat_vek_iba_rok() {
	time_t t = time(0);
	struct tm *teraz = localtime(&t);
	int dnes_rok = (teraz->tm_year + 1900);
	return(dnes_rok - vrat_rok());
}

int rodne_cislo::vrat_vek()
{
	int dni_v_mesiaci[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	int dnes_rok, dnes_mesiac, dnes_den, vek_rok, vek_mesiac, vek_den;
	time_t t = time(0);
	struct tm *teraz = localtime(&t);
	dnes_rok = (teraz->tm_year + 1900);
	dnes_mesiac = (teraz->tm_mon + 1);
	dnes_den = teraz->tm_mday;
	vek_rok = dnes_rok - vrat_rok();

	if (vrat_den() > dnes_den) {
		dnes_den = dnes_den + dni_v_mesiaci[vrat_mesiac() - 1];
		dnes_mesiac = dnes_mesiac - 1;
	}
	if (vrat_mesiac() > dnes_mesiac) {
		dnes_rok = dnes_rok - 1;
		dnes_mesiac = dnes_mesiac + 12;
	}
	vek_den = dnes_den - vrat_den();
	vek_mesiac = dnes_mesiac - vrat_mesiac();
	vek_rok = dnes_rok - vrat_rok();

	return(vek_den + (dni_v_mesiaci[vek_mesiac] * vek_mesiac) + (365 * vek_rok));
}

char *klient::vrat_meno()
{
	char *pom;
	pom = new char[20];
	strcpy(pom, meno);
	return pom;
}

char *klient::vrat_priezvisko()
{
	char *pom;
	pom = new char[20];
	strcpy(pom, priezvisko);
	return pom;
}

char *klient::vrat_povolanie()
{
	char *pom;
	pom = new char[20];
	strcpy(pom, povolanie);
	return pom;
}

char *klient::vrat_ulicu()
{
	char *pom;
	pom = new char[30];
	strcpy(pom, ulica);
	return pom;
}

char *klient::vrat_mesto()
{
	char *pom;
	pom = new char[30];
	strcpy(pom, mesto);
	return pom;
}

int klient::vrat_plat()
{
	int pom;
	pom = plat;
	return pom;
}

int klient::vrat_pocet_uverov()
{
	int pom;
	pom = pocet_uverov;
	return pom;
}

int klient::vrat_bonitu()
{
	int pom;
	pom = bonita;
	return pom;
}

int klient::vrat_sumu_uverov()
{
	int pom;
	pom = suma_uverov;
	return pom;
}

int klient::vrat_splacal_nacas()
{
	int pom;
	pom = splacal_nacas;
	return pom;
}

void klient::nastav_meno(char *m) {
	strcpy(meno, m);
}

void klient::nastav_priezvisko(char *p) {
	strcpy(priezvisko, p);
}

void klient::nastav_mesto(char *m) {
	strcpy(mesto, m);
}

void klient::nastav_ulicu(char *u) {
	strcpy(ulica, u);
}

void klient::nastav_povolanie(char *p) {
	strcpy(povolanie, p);
}

void klient::nastav_plat(int p) {
	plat = p;
}

void klient::nastav_pocet_uverov(int p) {
	pocet_uverov = p;
}

void klient::nastav_sumu_uverov(int s) {
	suma_uverov = s;
}

void klient::nastav_bonitu(int b) {
	bonita = b;
}

void klient::nastav_splacal_nacas(int s) {
	splacal_nacas = s;
}