from sqlalchemy import Column, Integer, DateTime, ForeignKey, Float, JSON
from sqlalchemy.orm import relationship

from app.infrastructure.database.models import Base


class DeliveryOrder(Base):
    __tablename__ = 'delivery_orders'

    id = Column(Integer, primary_key=True, autoincrement=True)
    order_datetime = Column(DateTime, nullable=False)
    count_trucks = Column(Integer, nullable=False)
    deadline = Column(DateTime, nullable=False)
    price = Column(Float, nullable=False)
    estimated_route_time_in_minutes = Column(Integer)
    route = Column(JSON)

    truck_id = Column(Integer, ForeignKey('trucks.id'))
    total_order_id = Column(Integer, ForeignKey('total_orders.id'))

    truck = relationship('Truck', back_populates='delivery_orders')
    total_order = relationship('TotalOrder', back_populates='delivery_orders')

    delivery_accessories = relationship('DeliveryAccessory', back_populates='delivery_order')
