from sqlalchemy import Column, Integer, String, Numeric, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from models._system import Base
from models.provisiongroup_pgro import ProvisiongroupPgro


class DealDeal(Base):
    __tablename__ = 'deal_deal'
    __table_args__ = {'mysql_engine': 'InnoDB'}

    id_deal = Column(
        Integer,
        primary_key=True,
        autoincrement=True
    )
    provisiongroup_deal = Column(
        Integer,
        ForeignKey('provisiongroup_pgro.id_pgro')
    )
    base_deal = Column(
        Integer,
        ForeignKey('base_base.id_base'),
        nullable=False
    )
    providercode_deal = Column(
        String(255)
    )
    name_deal = Column(
        String(255)
    )
    alias_deal = Column(
        String(255)
    )
    price_deal = Column(
        Numeric(8, 5),
        nullable=False
    )
    starts_deal = Column(
        DateTime,
        nullable=False
    )
    stops_deal = Column(
        DateTime
    )
    provision1_deal = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision2_deal = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision3_deal = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision4_deal = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    created_deal = Column(
        DateTime,
        nullable=False
    )
    updated_deal = Column(
        DateTime,
        nullable=False
    )

    base = relationship(
        "BaseBase",
        back_populates="deals"
    )
    provisiongroup = relationship(
        "ProvisiongroupPgro",
        back_populates="deals"
    )
