"""
Module for declaration of common constants available throughout Open Civic Data code.
"""

import re

DIVISION_ID_REGEX = r'^ocd-division/country:[a-z]{2}(/[^\W\d]+:[\w.~-]+)*$'
JURISDICTION_ID_REGEX = r'^ocd-jurisdiction/country:[a-z]{2}(/[^\W\d]+:[\w.~-]+)*/\w+$'

# helper for making options-only lists
_keys = lambda allopts: [opt[0] for opt in allopts]

"""
Policy on addition of new types here:

Because these lists are strictly enforced in lots of code for the purposes of data quality
we have a fairly liberal policy on amendment.

If a type is needed and is not duplicative of another type, it will be accepted.

At the moment, because of this policy, no method exists to extend these lists, instead we will
strive for them to be comprehensive.

The only exception to this would be translations, which should simply exist as translations of
the display name (2nd attribute).
"""

CONTACT_TYPE_CHOICES = (
    ('address', 'Postal Address'),
    ('email', 'Email'),
    ('url', 'URL'),
    ('fax', 'Fax'),
    ('text', 'Text Phone'),
    ('voice', 'Voice Phone'),
    ('video', 'Video Phone'),
    ('pager', 'Pager'),
    ('textphone', 'Device for people with hearing impairment'),
# NOTE: this list explicitly does not include RFC 6350s 'cell' as that is redundant with
# voice and the distinction will only lead to confusion.  contact_detail.note can be
# used to indicate if something is a home, work, cell, etc.
)
CONTACT_TYPES = _keys(CONTACT_TYPE_CHOICES)


JURISDICTION_CLASSIFICATION_CHOICES = (
    ('government', 'Government'),
    ('legislature', 'Legislature'),
    ('executive', 'Executive'),
    ('school_system', 'School System'),
)
JURISDICTION_CLASSIFICATIONS = _keys(JURISDICTION_CLASSIFICATION_CHOICES)


SESSION_CLASSIFICATION_CHOICES = (
    ('primary', 'Primary'),
    ('special', 'Special'),
)
SESSION_CLASSIFICATIONS = _keys(SESSION_CLASSIFICATION_CHOICES)


ORGANIZATION_CLASSIFICATION_CHOICES = (
    ('legislature', 'Legislature'),
    ('executive', 'Executive'),
    ('upper', 'Upper Chamber'),
    ('lower', 'Lower Chamber'),
    ('party', 'Party'),
    ('committee', 'Committee'),
    ('commission', 'Commission'),
)
ORGANIZATION_CLASSIFICATIONS = _keys(ORGANIZATION_CLASSIFICATION_CHOICES)

BILL_CLASSIFICATION_CHOICES = (
    ('bill', 'Bill'),
    ('resolution', 'Resolution'),
    ('concurrent resolution', 'Concurrent Resolution'),
    ('joint resolution', 'Joint Resolution'),
    ('memorial', 'Memorial'),
    ('commemoration', 'Commemoration'),
    ('concurrent memorial', 'Concurrent Memorial'),
    ('joint memorial', 'Joint Memorial'),
    ('proposed bill', 'Proposed Bill'),
    ('proclamation', 'Proclamation'),
    ('nomination', 'Nomination'),
    ('contract', 'Contract'),
    ('appointment', 'Appointment'),
    ('constitutional amendment', 'Constitutional Amendment'),
    ('petition', 'Petition'),
    ('concurrent order', 'Concurrent Order'),
    ('appropriation', 'Appropriation'),
)
BILL_CLASSIFICATIONS = _keys(BILL_CLASSIFICATION_CHOICES)

BILL_RELATION_TYPE_CHOICES = (
    ('companion', 'Companion'),             # a companion in another chamber
    ('prior-session', 'Prior Session'),     # an introduction from a prior session
    ('replaced-by', 'Replaced By'),         # a bill has been replaced by another
    ('replaces', 'Replaces'),               # a bill that replaces another
)
BILL_RELATION_TYPES = _keys(BILL_RELATION_TYPE_CHOICES)

BILL_ACTION_CLASSIFICATION_CHOICES = (
    ('filing', 'Filing'),
    ('introduction', 'Introduced'),
    ('reading-1', 'First Reading'),
    ('reading-2', 'Second Reading'),
    ('reading-3', 'Third Reading'),
    ('passage', 'Passage'),
    ('failure', 'Passage Failure'),
    ('withdrawal', 'Withdrawal'),
    ('substitution', 'Substitution'),
    ('amendment-introduction', 'Amendment Introduction'),
    ('amendment-passage', 'Amendment Passage'),
    ('amendment-withdrawal', 'Amendment Withdrawal'),
    ('amendment-failure', 'Amendment Failure'),
    ('amendment-amended', 'Amendment Amended'),
    ('committee-referral', 'Committee Referral'),
    ('committee-passage', 'Passage from Committee'),
    ('committee-passage-favorable', 'Favorable Passage from Committee'),
    ('committee-passage-unfavorable', 'Unfavorable Passage from Committee'),
    ('committee-failure', 'Failure in Committee'),
    ('executive-received', 'Received By Executive'),
    ('executive-signature', 'Signed By Executive'),
    ('executive-veto', 'Veto By Executive'),
    ('executive-veto-line-item', 'Line Item Veto By Executive'),
    ('veto-override-passage', 'Veto Override Passage'),
    ('veto-override-failure', 'Veto Override Failure'),
)
BILL_ACTION_CLASSIFICATIONS = _keys(BILL_ACTION_CLASSIFICATION_CHOICES)

VOTE_CLASSIFICATION_CHOICES = (
    ('bill-passage', 'Bill Passage'),
    ('amendment-passage', 'Amendment Passage'),
    ('veto-override', 'Veto Override'),
)
VOTE_CLASSIFICATIONS = _keys(VOTE_CLASSIFICATION_CHOICES)

VOTE_OPTION_CHOICES = (
    ('yes', 'Yes'),
    ('no', 'No'),
    ('absent', 'Absent'),
    ('abstain', 'Abstain'),
    ('not voting', 'Not Voting'),
    ('paired', 'Paired'),
    ('excused', 'Excused'),

    # Only for open states.
    ('other', 'Other'),
)
VOTE_OPTIONS = _keys(VOTE_OPTION_CHOICES)

VOTE_RESULT_CHOICES = (
    ('pass', 'Pass'),
    ('fail', 'Fail'),
)
VOTE_RESULTS = _keys(VOTE_RESULT_CHOICES)

@@ -2932,24 +2932,55 @@
 priation'),%0A
+    ('ordinance', 'Ordinance')%0A
 )%0ABILL_CLASS

add ordinance as bill_classification option