"""Add ebom tables

Revision ID: 00817cda9d17
Revises: a904d0d1e1a7
Create Date: 2016-09-01 14:05:49.858683

"""

# revision identifiers, used by Alembic.
from sqlalchemy.orm import backref
from helix.constants.inverter_type import InverterType

revision = '00817cda9d17'
down_revision = 'a904d0d1e1a7'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table(
        'power_stations',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('site_id', sa.Integer, sa.ForeignKey('sites.id')),
        sa.Column('quantity', sa.Integer, nullable=False),
        sa.Column('ac_run_length', sa.Integer, nullable=False),
        sa.Column('description', sa.Unicode, nullable=False),
    )

    op.create_table(
        'standalone_inverters',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('site_id', sa.Integer, sa.ForeignKey('sites.id')),
        sa.Column('attachment_point_id', sa.Integer, sa.ForeignKey('power_stations.id')),
        sa.Column('ac_run_length', sa.Integer, nullable=False),
    )

    op.create_table(
        'inverters',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('model', sa.Enum(str(InverterType.SMA.MODEL_12KW.value), str(InverterType.SMA.MODEL_15KW.value), str(InverterType.SMA.MODEL_20KW.value), str(InverterType.SMA.MODEL_24KW.value), name='InverterType'), nullable=False),
        sa.Column('strings_per_inverter', sa.Integer, nullable=False),
        sa.Column('sunshade', sa.Boolean),
        sa.Column('dc_switch', sa.Boolean),
        sa.Column('power_station_id', sa.Integer, sa.ForeignKey('power_stations.id')),
        sa.Column('standalone_inverter_id', sa.Integer, sa.ForeignKey('standalone_inverters.id')),
    )

    op.create_table(
        'power_monitors',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('site_id', sa.Integer, sa.ForeignKey('sites.id')),
        sa.Column('power_station_id', sa.Integer, sa.ForeignKey('power_stations.id'))
    )


def downgrade():
    op.drop_table('inverters')
    op.drop_table('power_monitors')
    op.drop_table('power_stations')
    op.drop_table('standalone_inverters')
    sa.Enum(name='InverterType').drop(op.get_bind(), checkfirst=False)
