import datetime
import pytz
from enum import Enum as PyEnum
from sqlalchemy import Column, Integer, Float, DateTime, JSON, BigInteger, ForeignKey, Enum, Boolean
from backend.app.db.base import Base


class Solar(Base):
    __tablename__ = 'solar'
    id = Column(Integer, primary_key=True, autoincrement=True)
    longitude = Column(Float, nullable=False)
    latitude = Column(Float, nullable=False)
    uprn = Column(Integer, nullable=False)
    created_at = Column(
        DateTime, nullable=False, default=datetime.datetime.now(pytz.utc)
    )
    updated_at = Column(
        DateTime, nullable=False, default=datetime.datetime.now(pytz.utc), onupdate=datetime.datetime.now(pytz.utc)
    )
    google_api_response = Column(JSON, nullable=False)


class ScenarioType(PyEnum):
    unit = "unit"
    building = "building"


class SolarScenario(Base):
    __tablename__ = 'solar_scenario'

    id = Column(BigInteger, primary_key=True, autoincrement=True)
    solar_id = Column(BigInteger, ForeignKey('solar.id'), nullable=False)
    scenario_type = Column(Enum(ScenarioType), nullable=False)
    number_panels = Column(Integer, nullable=False)
    array_kwhp = Column(Integer, nullable=False)
    lifetime_dc_kwh = Column(Float, nullable=False)
    yearly_dc_kwh = Column(Float, nullable=False)
    lifetime_ac_kwh = Column(Float)
    yearly_ac_kwh = Column(Float)
    cost = Column(Float, nullable=False)
    expected_payback_years = Column(Float)
    panelled_roof_area = Column(Float, nullable=False)
    is_default = Column(Boolean, nullable=False)
