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 OptionOpti(Base):
    __tablename__ = 'option_opti'
    __table_args__ = {'mysql_engine': 'InnoDB'}

    id_opti = Column(
        Integer,
        primary_key=True,
        autoincrement=True
    )
    provisiongroup_opti = Column(
        Integer,
        ForeignKey('provisiongroup_pgro.id_pgro')
    )
    base_opti = Column(
        Integer,
        ForeignKey('base_base.id_base'),
        nullable=False
    )
    providercode_opti = Column(
        String(255)
    )
    providercategory_opti = Column(
        String(255)
    )
    name_opti = Column(
        String(255),
        nullable=False
    )
    alias_opti = Column(
        String(255)
    )
    price_opti = Column(
        Numeric(8, 5),
        nullable=False
    )
    starts_opti = Column(
        DateTime,
        nullable=False
    )
    stops_opti = Column(
        DateTime
    )
    provision1_opti = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision2_opti = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision3_opti = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    provision4_opti = Column(
        Numeric(10, 5),
        nullable=False,
        default=0.00000
    )
    created_opti = Column(
        DateTime,
        nullable=False
    )
    updated_opti = Column(
        DateTime,
        nullable=False
    )

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