from django.views import View

from Object.ResponseObject import ResponseObject


class DeviceCommonView(View):
    def get(self, request, *args, **kwargs):
        request.encoding = 'utf-8'
        operation = kwargs.get('operation')
        request_dict = request.GET
        return self.validation(request, request_dict, operation)

    def post(self, request, *args, **kwargs):
        request.encoding = 'utf-8'
        operation = kwargs.get('operation')
        request_dict = request.POST
        return self.validation(request, request_dict, operation)

    def validation(self, request, request_dict, operation):
        language = request_dict.get('language', 'en')
        response = ResponseObject(language)
        if operation == 'getDomain':
            return self.get_domain(response)

    @staticmethod
    def get_domain(response):
        data = [
            {"title": "国内", "server": "https://www.zositechc.cn/", "push": "https://push.zositechc.cn/"},
            {"title": "美洲", "server": "https://www.dvema.com/", "push": "https://push.dvema.com/"},
            {"title": "欧洲", "server": "https://www.zositeche.com/", "push": "https://push.zositeche.com/"},
            {"title": "测试", "server": "https://test.zositechc.cn/", "push": "https://test.push.zositechc.cn/"},
        ]
        return response.json(0, data)
