# -*- coding: utf-8 -*-

# Copyright (C) 2013-2014 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

from sqlalchemy.schema import Column, PrimaryKeyConstraint, Index
from sqlalchemy.sql.schema import CheckConstraint
from sqlalchemy.types import Integer, String, Enum, Text

from xivo_dao.helpers.db_manager import Base


class Queue(Base):

    __tablename__ = 'queue'
    __table_args__ = (
        PrimaryKeyConstraint('name'),
        Index('queue__idx__category', 'category'),
        CheckConstraint("autopause in ('no', 'yes', 'all')")
    )

    name = Column(String(128))
    musicclass = Column(String(128))
    announce = Column(String(128))
    context = Column(String(39))
    timeout = Column(Integer, server_default='0')
    monitor_type = Column('monitor-type', Enum('no', 'mixmonitor', name='queue_monitor_type', metadata=Base.metadata))
    monitor_format = Column('monitor-format', String(128))
    queue_youarenext = Column('queue-youarenext', String(128))
    queue_thereare = Column('queue-thereare', String(128))
    queue_callswaiting = Column('queue-callswaiting', String(128))
    queue_holdtime = Column('queue-holdtime', String(128))
    queue_minutes = Column('queue-minutes', String(128))
    queue_seconds = Column('queue-seconds', String(128))
    queue_thankyou = Column('queue-thankyou', String(128))
    queue_reporthold = Column('queue-reporthold', String(128))
    periodic_announce = Column('periodic-announce', Text)
    announce_frequency = Column('announce-frequency', Integer)
    periodic_announce_frequency = Column('periodic-announce-frequency', Integer)
    announce_round_seconds = Column('announce-round-seconds', Integer)
    announce_holdtime = Column('announce-holdtime', String(4))
    retry = Column(Integer)
    wrapuptime = Column(Integer)
    maxlen = Column(Integer)
    servicelevel = Column(Integer)
    strategy = Column(String(11))
    joinempty = Column(String(255))
    leavewhenempty = Column(String(255))
    ringinuse = Column(Integer, nullable=False, server_default='0')
    reportholdtime = Column(Integer, nullable=False, server_default='0')
    memberdelay = Column(Integer)
    weight = Column(Integer)
    timeoutrestart = Column(Integer, nullable=False, server_default='0')
    commented = Column(Integer, nullable=False, server_default='0')
    category = Column(Enum('group', 'queue', name='queue_category', metadata=Base.metadata), nullable=False)
    timeoutpriority = Column(String(10), nullable=False, server_default='app')
    autofill = Column(Integer, nullable=False, server_default='1')
    autopause = Column(String(3), nullable=False, server_default='no')
    setinterfacevar = Column(Integer, nullable=False, server_default='0')
    setqueueentryvar = Column(Integer, nullable=False, server_default='0')
    setqueuevar = Column(Integer, nullable=False, server_default='0')
    membermacro = Column(String(1024))
    min_announce_frequency = Column('min-announce-frequency', Integer, nullable=False, server_default='60')
    random_periodic_announce = Column('random-periodic-announce', Integer, nullable=False, server_default='0')
    announce_position = Column('announce-position', String(1024), nullable=False, server_default='yes')
    announce_position_limit = Column('announce-position-limit', Integer, nullable=False, server_default='5')
    defaultrule = Column(String(1024))
