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

"""This file is a demo for what the dynamiclly generated code would be like.
"""

from thriftpy.thrift import (
    TPayload,
    TException,
    TType,
)

DEFAULT_LIST_SIZE = 10


class PhoneType(object):
    MOBILE = 0
    HOME = 1
    WORK = 2


class PhoneNumber(TPayload):
    thrift_spec = {
        1: (TType.I32, "type"),
        2: (TType.STRING, "number"),
    }


class Person(TPayload):
    thrift_spec = {
        1: (TType.STRING, "name"),
        2: (TType.LIST, "phones", (TType.STRUCT, PhoneNumber)),
        4: (TType.I32, "created_at"),
    }


class AddressBook(TPayload):
    thrift_spec = {
        1: (TType.MAP, "people",
            (TType.STRING, (TType.STRUCT, Person)))
    }


class PersonNotExistsError(TException):
    thrift_spec = {
        1: (TType.STRING, "message")
    }


class AddressBookService(object):
    thrift_services = [
        "ping",
        "add",
        "remove",
        "get",
        "book",
        "get_phones",
    ]

    class ping_args(TPayload):
        thrift_spec = {}

    class ping_result(TPayload):
        thrift_spec = {}

    class add_args(TPayload):
        thrift_spec = {
            1: (TType.STRUCT, "person", Person),
        }

    class add_result(TPayload):
        thrift_spec = {
            0: (TType.BOOL, "success"),
        }

    class remove_args(TPayload):
        thrift_spec = {
            1: (TType.STRING, "name"),
        }

    class remove_result(TPayload):
        thrift_spec = {
            0: (TType.BOOL, "success"),
            1: (TType.STRUCT, "not_exists", PersonNotExistsError)
        }

    class get_args(TPayload):
        thrift_spec = {
            1: (TType.STRING, "name"),
        }

    class get_result(TPayload):
        thrift_spec = {
            0: (TType.STRUCT, "success", Person),
        }

    class book_args(TPayload):
        thrift_spec = {}

    class book_result(TPayload):
        thrift_spec = {
            0: (TType.STRUCT, "success", AddressBook),
        }

    class get_phones_args(TPayload):
        thrift_spec = {
            1: (TType.STRING, "name"),
        }

    class get_phones_result(TPayload):
        thrift_spec = {
            0: (TType.MAP, "success", (TType.I32, TType.STRING)),
        }

@@ -383,32 +383,86 @@
 number%22),%0A    %7D%0A
+    default_spec = %5B(%22type%22, None), (%22number%22, None)%5D%0A
 %0A%0Aclass Person(T
@@ -630,24 +630,100 @@
 at%22),%0A    %7D%0A
+    default_spec = %5B(%22name%22, None), (%22phones%22, None), (%22created_at%22, None)%5D%0A
 %0A%0Aclass Addr
@@ -844,32 +844,70 @@
 Person)))%0A    %7D%0A
+    default_spec = %5B(%22people%22, None)%5D%0A
 %0A%0Aclass PersonNo
@@ -995,16 +995,55 @@
 )%0A    %7D%0A
+    default_spec = %5B(%22message%22, None)%5D%0A
 %0A%0Aclass 
@@ -1250,32 +1250,58 @@
 thrift_spec = %7B%7D
+%0A        default_spec = %5B%5D
 %0A%0A    class ping
@@ -1335,32 +1335,58 @@
 thrift_spec = %7B%7D
+%0A        default_spec = %5B%5D
 %0A%0A    class add_
@@ -1475,32 +1475,74 @@
 rson),%0A        %7D
+%0A        default_spec = %5B(%22person%22, None)%5D
 %0A%0A    class add_
@@ -1624,32 +1624,75 @@
 ess%22),%0A        %7D
+%0A        default_spec = %5B(%22success%22, None)%5D
 %0A%0A    class remo
@@ -1774,32 +1774,72 @@
 ame%22),%0A        %7D
+%0A        default_spec = %5B(%22name%22, None)%5D
 %0A%0A    class remo
@@ -1990,32 +1990,97 @@
 Error)%0A        %7D
+%0A        default_spec = %5B(%22success%22, None), (%22not_exists%22, None)%5D
 %0A%0A    class get_
@@ -2159,32 +2159,72 @@
 ame%22),%0A        %7D
+%0A        default_spec = %5B(%22name%22, None)%5D
 %0A%0A    class get_
@@ -2315,33 +2315,164 @@
 erson),%0A        
-%7D
+    1: (TType.STRUCT, %22not_exists%22, PersonNotExistsError)%0A        %7D%0A        default_spec = %5B(%22success%22, None), (%22not_exists%22, None)%5D
 %0A%0A    class book
@@ -2512,16 +2512,42 @@
 pec = %7B%7D
+%0A        default_spec = %5B%5D
 %0A%0A    cl
@@ -2653,32 +2653,75 @@
 Book),%0A        %7D
+%0A        default_spec = %5B(%22success%22, None)%5D
 %0A%0A    class get_
@@ -2815,16 +2815,56 @@
        %7D
+%0A        default_spec = %5B(%22name%22, None)%5D
 %0A%0A    cl
@@ -2984,20 +2984,63 @@
 STRING)),%0A        %7D%0A
+        default_spec = %5B(%22success%22, None)%5D%0A

update addressbook.py demo, add default_spec.