#include "domain.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

Material* _Material_Constructor(char *name, char *supplier, int quantity, int day, int month, int year)
{
    Material* m =(Material*)malloc(sizeof(Material));
    m->name=name;
    m->supplier=supplier;
    m->quantity = quantity;
    m->expiration_date.tm_mday = day;
    m->expiration_date.tm_mon = month-1;
    m->expiration_date.tm_year = year;
    return m;
}



void _Material_Destructor(Material *material){
    free(material->name);
    free(material->supplier);
    free(material);
}

char* _Material_GetName(Material *material){
    return material->name;
}

char* _Material_GetSupplier(Material *material){
    return material->supplier;
}

int _Material_GetQuantity(Material *material){
    return material->quantity;
}

struct tm _Material_GetDate(Material *material){
    return material->expiration_date;
}

void _Material_SetQuantity(Material *material, int quantity){
    material->quantity = quantity;
}

char* _Material_stringify(Material *material){
    char* string =(char*)malloc(sizeof(char)*255);
    sprintf(string,"Name: %s | Supplier: %s | Quantity: %d | Expiration Date: %02d/%02d/%d\n",material->name,material->supplier,material->quantity,material->expiration_date.tm_mday,material->expiration_date.tm_mon+1,material->expiration_date.tm_year);
    return string;
}
