# coding: utf-8
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from kpi.filters import SearchFilter
from .base import BaseViewSet
from ..models.language import Language
from ..serializers import LanguageSerializer


class LanguageViewSet(BaseViewSet):
    """

    Lists the languages accessible to requesting (authenticated) user.

    <pre class="prettyprint">
    <b>GET</b> /api/v2/languages/
    </pre>

    > Example
    >
    >       curl -X GET https://[kpi]/api/v2/languages/

    Search can be made with `q` parameter. By default, search for the term in language names or language codes.

    > Example
    >
    >       curl -X GET https://[kpi]/api/v2/languages/?q=fr
    >       {
    >           "count": 41
    >           "next": ...
    >           "previous": ...
    >           "results": [
    >               {
    >                   "name": "French",
    >                   "code": "fr",
    >                   "featured": true,
    >                   ...
    >               },
    >               {
    >                   "name": "Gula (Central African Republic)",
    >                   "code": "kcm",
    >                   "featured": false,
    >                   ...
    >               },
    >           ]
    >       }

    Complex searches can be done on other fields, such as `transcription_services` and `translation_services`.

    > Example
    >
    >       curl -X GET https://[kpi]/api/v2/languages/?q=transcription_services__code:goog AND translation_services__code:goog
    >       {
    >           "count": 1
    >           "next": ...
    >           "previous": ...
    >           "results": [
    >               {
    >                   "name": "English",
    >                   "code": "en",
    >                   "featured": true,
    >                   "transcription_services": [
    >                       {
    >                           "code": "goog",
    >                           "name": "Google"
    >                       }
    >                   ],
    >                   "translation_services": [
    >                       {
    >                           "code": "goog",
    >                           "name": "Google"
    >                       },
    >                   ],
    >               },
    >           ]
    >       }

    Results are order by `featured` first (descending order), then by their name.


    ## Get one language

    * `code` - is the unique identifier of a specific language

    <pre class="prettyprint">
    <b>GET</b> /api/v2/languages/<code>{code}</code>/
    </pre>

    > Example
    >
    >       curl -X GET https://[kpi]/api/v2/languages/fr/
    >       {
    >           "name": "French",
    >           "code": "fr",
    >           "featured": true,
    >           "transcription_services": [
    >               {
    >                   "code": "goog",
    >                   "name": "Google"
    >               }
    >           ],
    >           "translation_services": [
    >               {
    >                   "code": "goog",
    >                   "name": "Google"
    >               },
    >           ],
    >       }


    ### CURRENT ENDPOINT
    """

    serializer_class = LanguageSerializer
    min_search_characters = 2
    queryset = Language.objects.all()

@@ -1949,36 +1949,84 @@
        %22
-code%22: %22goog
+goog%22: %7B%0A    %3E                               %22en-CA%22: %22en-CA
 %22,%0A    %3E
         
@@ -2009,32 +2009,36 @@
 : %22en-CA%22,%0A    %3E
+    
                 
@@ -2045,39 +2045,127 @@
            %22
-name%22: %22Google%22
+en-GB%22: %22en-GB%22,%0A    %3E                               %22en-US%22: %22en-US%22%0A    %3E                           %7D
 %0A    %3E      
@@ -2321,32 +2321,26 @@
         
- %22code%22:
  %22goog%22
-,
+: %7B
 %0A    %3E  
@@ -2364,32 +2364,31 @@
         
-%22name%22: %22Google%22
+    %22en%22: %22en%22,
 %0A    %3E  
@@ -2400,34 +2400,67 @@
                 
+    %7D%0A    %3E                       
 %7D
-,
 %0A    %3E          
@@ -2461,33 +2461,32 @@
                %5D
-,
 %0A    %3E          
@@ -2485,32 +2485,56 @@
              %7D,%0A
+    %3E               ...%0A
     %3E           
@@ -3097,36 +3097,76 @@
            %22
-code%22: %22goog
+goog%22: %7B%0A    %3E                       %22fr-CA%22: %22fr-CA
 %22,%0A    %3E    
@@ -3180,38 +3180,46 @@
         
-%22name%22: %22Google
+    %22fr-FR%22: %22fr-FR
 %22%0A    %3E
+    
         
@@ -3224,32 +3224,55 @@
          %7D%0A    %3E
+               %7D%0A    %3E 
            %5D,%0A  
@@ -3266,32 +3266,33 @@
         %5D,%0A    %3E
+ 
            %22tran
@@ -3324,32 +3324,33 @@
 %3E               
+ 
 %7B%0A    %3E         
@@ -3363,23 +3363,18 @@
     
-%22code%22:
  %22goog%22
-,
+: %7B
 %0A   
@@ -3398,24 +3398,24 @@
     
-%22name%22: %22Google%22
+     %22fr%22: %22fr%22,
 %0A   
@@ -3427,32 +3427,60 @@
             
-%7D,%0A    %3E
+     %7D%0A    %3E                %7D%0A    %3E 
            %5D
@@ -3471,33 +3471,32 @@
   %3E            %5D
-,
 %0A    %3E       %7D%0A%0A

Update API documentation to include language regions