from sqlalchemy.sql import func
from sqlalchemy.dialects import postgresql
from webinterface import db

class sArchivosGTFS(db.Model):
    __tablename__   = 'gtfs'
    __bind_key__    = 'gtfs_static'
    id              = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    descripcion     = db.Column(db.String)
    file            = db.Column(db.String)
    hash            = db.Column(db.String)
    size            = db.Column(db.Integer)
    loaded          = db.Column(db.Integer, default=0)
    ts              = db.Column(db.Datetime, default=func.now())

#agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url
#DTPR,División de Transporte Público Regional,http://www.dtpr.gob.cl/,America/Santiago,es,+562 2421 3580,
class sAgencia(db.Model):
    __tablename__   = 'agency'
    __bind_key__    = 'gtfs_static'
    id              = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    agency_id       = db.Column(db.String)
    agency_name     = db.Column(db.String)
    agency_url      = db.Column(db.String)
    agency_timezone = db.Column(db.String)
    agency_lang     = db.Column(db.String)
    agency_phone    = db.Column(db.String)
    agency_fare_url = db.Column(db.String)

#service_id,start_date,end_date,monday,tuesday,wednesday,thursday,friday,saturday,sunday
#S,20210101,20311231,0,0,0,0,0,1,0
#D,20210101,20311231,0,0,0,0,0,0,1
#L,20210101,20311231,1,1,1,1,1,0,0
class sCalendario(db.Model):
    __tablename__ = 'calendar'
    __bind_key__ = 'gtfs_static'
    id              = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    service_id      = db.Column(db.String)
    start_date      = db.Column(db.String)
    end_date        = db.Column(db.String)
    monday          = db.Column(db.Integer)
    tuesday         = db.Column(db.Integer)
    wednesday       = db.Column(db.Integer)
    thursday        = db.Column(db.Integer)
    friday          = db.Column(db.Integer)
    saturday        = db.Column(db.Integer)
    sunday          = db.Column(db.Integer)

#feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version
#División de Transporte Público Regional,http://www.dtpr.gob.cl/,es,20210101,20311231,Gran Concepción20220616
class sFeedInfo(db.Model):
    __tablename__ = 'feed_info'
    __bind_key__ = 'gtfs_static'
    id              = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    feed_publisher_name = db.Column(db.String)
    feed_publisher_url  = db.Column(db.String)
    feed_lang           = db.Column(db.String)
    feed_start_date     = db.Column(db.String)
    feed_end_date       = db.Column(db.String)
    feed_version        = db.Column(db.String)

#route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color
#625,DTPR,70KH,Nonguén - Parque Tumbes,,3,,0d7215,ffffff
#600,DTPR,41CR,Parque Empresarial Biobío - Terminal Collao,,3,,ad0101,ffffff
class sRuta(db.Model):
    __tablename__ = 'routes'
    __bind_key__ = 'gtfs_static'

    id          = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    route_id            = db.Column(db.String)
    agency_id           = db.Column(db.String)
    route_short_name    = db.Column(db.String)
    route_long_name     = db.Column(db.String)
    route_desc          = db.Column(db.String)
    route_type          = db.Column(db.Integer)
    route_url           = db.Column(db.String)
    route_color         = db.Column(db.String)
    route_text_color    = db.Column(db.String)

#shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled
#1136979693,-36.843,-73.00984,1
#1136979693,-36.843,-73.00984,2
class sFormas(db.Model):
    __tablename__ = 'shapes'
    __bind_key__ = 'gtfs_static'

    id                  = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    shape_id            = db.Column(db.String)
    shape_pt_lat        = db.Column(db.Double)
    shape_pt_lon        = db.Column(db.Double)
    shape_pt_sequence   = db.Column(db.Integer)
    shape_dist_traveled = db.Column(db.Double)

#stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,wheelchair_boarding
#40921,,Pque Zoologico Concepcion  Poniente,,-36.8400453,-73.00696914,,,,,
#40808,,Cno. Nonguen esq Las Vertientes,,-36.83675878,-73.00343935,,,,,
class sParadas(db.Model):
    __tablename__ = 'stops'
    __bind_key__ = 'gtfs_static'

    id                  = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    stop_id             = db.Column(db.String)
    stop_code           = db.Column(db.String)
    stop_name           = db.Column(db.String)
    stop_desc           = db.Column(db.String)
    stop_lat            = db.Column(db.Double)
    stop_lon            = db.Column(db.Double)
    zone_id             = db.Column(db.String)
    stop_url            = db.Column(db.String)
    location_type       = db.Column(db.Integer)
    parent_station      = db.Column(db.String)
    wheelchair_boarding = db.Column(db.Integer)
#trip_id,arrival_time,departure_time,stop_id,stop_sequence,                                        timepoint,shape_dist_traveled
#trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,timepoint
#c8b17d5f-4-76aabf89-b,05:01:00,05:01:00,40439,1,,,,1
#c8b17d5f-4-76aabf89-b,05:02:00,05:02:00,40440,2,,,,0
class sDetenciones(db.Model):
    __tablename__ = 'stop_times'
    __bind_key__ = 'gtfs_static'

    id              = db.Column(db.Integer,  primary_key=True, nullable=False, autoincrement=True)

    trip_id         = db.Column(db.String)
    arrival_time    = db.Column(db.String)
    departure_time  = db.Column(db.String)
    stop_id         = db.Column(db.String)
    stop_sequence   = db.Column(db.Integer)
    stop_headsign   = db.Column(db.String)
    pickup_type     = db.Column(db.Integer)
    drop_off_type   = db.Column(db.Integer)
    timepoint       = db.Column(db.Integer)
#,,,,,,

#route_id,service_id,trip_id,trip_headsign,                direction_id,block_id,shape_id,wheelchair_accessible,bikes_allowed
#route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,block_id,shape_id,wheelchair_accessible,bikes_allowed
#625,S,c8b17d5f-4-76aabf89-b,Nonguén,,1,,1136979694,,
#625,S,4d018d35-7-76aabf89-b,Parque Tumbes,,0,,1136979693,,
#ac48288b-1-56195eaf-8,b1910f5b,1,0,1168259538,,0,0,1-1,1
#d9e94be9-f-56195eaf-8,b1910f5b,1,0,1168259538,,0,0,1-1,2
class sServicio(db.Model):
    __tablename__ = 'trips'
    __bind_key__ = 'gtfs_static'

    id                      = db.Column(db.String,  primary_key=True, nullable=False)

    route_id                = db.Column(db.String) # Ruta.rutaid
    service_id              = db.Column(db.String)
    trip_id                 = db.Column(db.String)
    trip_headsign           = db.Column(db.String)
    trip_short_name         = db.Column(db.String)
    direction_id            = db.Column(db.Integer)
    block_id                = db.Column(db.String)
    shape_id                = db.Column(db.String)
    wheelchair_accessible   = db.Column(db.Integer)
    bikes_allowed           = db.Column(db.Integer)

# 4cc08782-c-76aabf89-b
