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

from django.db import models
from django.utils.translation import ugettext_lazy as _

from utils.version_utils import is_version_match


class PlatformMixin(models.Model):
    BOTH = 0
    ADR = 1
    IOS = 2

    SUPPORT_PLATFORM = (
        (BOTH, u'全平台'),
        (ADR, u'Android'),
        (IOS, u'iOS'),
    )

    platform = models.IntegerField(_(u'plat'), choices=SUPPORT_PLATFORM, default=BOTH, help_text=u'支持平台', db_index=True)

    class Meta:
        abstract = True

    Platforms = {
        'ios': IOS,
        'iOS': IOS,
        'adr': ADR,
        'android': ADR,
        'Android': ADR,
    }


class VersionMixin(models.Model):
    min_adr = models.CharField(_(u'min_adr'), max_length=16, blank=True, null=True, help_text=u'Adr 最低版本')
    min_ios = models.CharField(_(u'min_ios'), max_length=16, blank=True, null=True, help_text=u'iOS 最低版本')
    max_adr = models.CharField(_(u'max_adr'), max_length=16, blank=True, null=True, help_text=u'Adr 最高版本')
    max_ios = models.CharField(_(u'max_ios'), max_length=16, blank=True, null=True, help_text=u'iOS 最高版本')

    def version_match(self, request):
        return is_version_match(request, {
            'min_adr': self.min_adr,
            'min_ios': self.min_ios,
            'max_adr': self.max_adr,
            'max_ios': self.max_ios,
        })

    class Meta:
        abstract = True


class PaiaiSrcMixin(models.Model):
    PAIAI_USER = 0
    PAIAI_LENSMAN = 1
    PAIAI_LENSMAN2 = 10
    PAIAI_TOURGUIDE = 2

    SRC = (
        (PAIAI_USER, u'拍爱用户端'),
        (PAIAI_LENSMAN, u'拍爱摄影师端'),
        (PAIAI_LENSMAN2, u'拍爱摄影师端2'),
        (PAIAI_TOURGUIDE, u'拍爱导游端'),
    )

    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'来源', db_index=True)

    class Meta:
        abstract = True


class LensmanTypeChoicesMixin(models.Model):
    NOTLENSMAN = -1
    COMMON = 0
    OUTTAKE = 10

    LENSMAN_TYPE = (
        (COMMON, u'普通摄影师'),
        (OUTTAKE, u'花絮摄影师'),
    )

    class Meta:
        abstract = True


class LensmanTypeMixin(LensmanTypeChoicesMixin):
    lensman_type = models.IntegerField(_(u'lensman_type'), choices=LensmanTypeChoicesMixin.LENSMAN_TYPE, default=LensmanTypeChoicesMixin.NOTLENSMAN, help_text=u'摄影师类别', db_index=True)

    class Meta:
        abstract = True


class LensmanTypeBoolMixin(LensmanTypeChoicesMixin):
    is_common_lensman = models.BooleanField(_(u'is_common_lensman'), default=False, help_text=u'是否为普通摄影师', db_index=True)
    is_outtake_lensman = models.BooleanField(_(u'is_outtake_lensman'), default=False, help_text=u'是否为花絮摄影师', db_index=True)

    class Meta:
        abstract = True
