package com.mlavrik.weatherapp.database;

import com.google.gson.Gson;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.mlavrik.weatherapp.models.daily.DailyWeatherData;


@DatabaseTable(tableName = "daily_weather")
public class DailyWeatherORM {
    public static final String CITY_FIELD = "city";
    public static final String DATA_FIELD = "data_field";

    @DatabaseField(generatedId = true, unique = true)
    private int _id;
    @DatabaseField(canBeNull = false, dataType = DataType.STRING, columnName = CITY_FIELD)
    private String city;
    @DatabaseField(dataType = DataType.STRING, columnName = DATA_FIELD)
    private String data;

    public DailyWeatherORM() {
    }

    public DailyWeatherORM(DailyWeatherData dailyWeatherData) {
        Gson gson = new Gson();
        this.city = dailyWeatherData.getName();
        this.data = gson.toJson(dailyWeatherData);
    }

    public DailyWeatherData getData() {
        Gson gson = new Gson();
        return gson.fromJson(data, DailyWeatherData.class);
    }


    public String getCity() {
        return city;
    }
}
