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

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

from pai2.basemodels import CreateUpdateMixin
from utils.url_utils import img_url


class UUIDInfo(CreateUpdateMixin):
    uuid = models.CharField(_(u'uuid'), max_length=22, blank=True, null=True, help_text=u'唯一标识', db_index=True, unique=True)
    lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True)

    class Meta:
        verbose_name = _('uuidinfo')
        verbose_name_plural = _('uuidinfo')

    def __unicode__(self):
        return u'{0.pk}'.format(self)

    @property
    def data(self):
        return {
            'pk': self.pk,
            'uuid': self.uuid,
            'lensman_id': self.lensman_id,
        }


class PhotosInfo(CreateUpdateMixin):
    lensman_id = models.CharField(_(u'lensman_id'), max_length=255, blank=True, null=True, help_text=u'摄影师唯一标识', db_index=True)
    session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识', db_index=True)
    photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'照片唯一标识', db_index=True)
    p_photo_path = models.CharField(_(u'p_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径，Box上传，有水印，服务器添加')
    m_photo_path = models.CharField(_(u'm_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径，Box上传，无水印')
    l_photo_path = models.CharField(_(u'l_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径，美化大图')
    r_photo_path = models.CharField(_(u'r_photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径，高清大图')

    class Meta:
        verbose_name = _('photosinfo')
        verbose_name_plural = _('photosinfo')
        index_together = [
            ['lensman_id', 'session_id'],
        ]
        unique_together = (
            ('lensman_id', 'session_id', 'photo_id'),
        )

    def __unicode__(self):
        return u'{0.pk}'.format(self)

    @property
    def p_photo_url(self):
        return img_url(self.p_photo_path)

    @property
    def m_photo_url(self):
        return img_url(self.m_photo_path)

    @property
    def l_photo_url(self):
        return img_url(self.l_photo_path)

    @property
    def r_photo_url(self):
        return img_url(self.r_photo_path)

    @property
    def data(self):
        return {
            'pk': self.pk,
            'user_id': self.lensman_id,
            'session_id': self.session_id,
            'photo_id': self.photo_id,
        }

    @property
    def detail(self):
        return {
            'pk': self.pk,
            'user_id': self.lensman_id,
            'session_id': self.session_id,
            'photo_id': self.photo_id,
            'photo_url': self.p_photo_url,
        }
