from tabnanny import verbose
from django.db import models
from utils.model import BaseModel
from apps.system.models import User, CommonAModel, Dict
# Create your models here.

class Video(CommonAModel):

    name = models.CharField(verbose_name='视频名称', max_length=100)
    category_big = models.ForeignKey(Dict, verbose_name='视频大类', on_delete=models.SET_NULL, null=True, blank=True, related_name='video_catebig')
    category = models.ForeignKey(Dict, verbose_name='视频分类', on_delete=models.SET_NULL, null=True, blank=True, related_name='video_cate')
    description = models.TextField(verbose_name='视频描述', default='')
    fileid = models.CharField(verbose_name='云点播视频id', unique=True, max_length=200)
    mediaurl = models.CharField(verbose_name='视频地址', max_length=200)
    coverurl = models.CharField(verbose_name='封面地址', max_length=200)
    duration = models.IntegerField(verbose_name='时长(秒)', default=0)
    views = models.IntegerField(verbose_name='总观看次数', default=0)
    viewsp = models.IntegerField(verbose_name='总观看人数', default=0)
    sort_str = models.CharField('排序字符', max_length=10, null=True, blank=True)

    class Meta:
        verbose_name = '点播视频'
        verbose_name_plural = verbose_name


    

class ViewRecord(BaseModel):
    """
    某视频-某人的观看记录统计
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='观看人', related_name='viewrecord_user')
    current = models.IntegerField(verbose_name='当前观看进度(秒)', default=0)
    video = models.ForeignKey(Video, verbose_name='点播视频', on_delete=models.CASCADE, related_name='viewrecord_video')
    views = models.IntegerField(verbose_name='总观看次数', default=0)
    total_seconds = models.PositiveIntegerField(verbose_name='总观看秒数', default=0)
    
    class Meta:
        verbose_name = '点播观看记录'
        verbose_name_plural = verbose_name


class ViewItem(BaseModel):
    """
    单次观看记录
    """
    create_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='观看人', related_name='viewitem_user')
    video = models.ForeignKey(Video, verbose_name='点播视频', on_delete=models.CASCADE, related_name='viewitem_video')
    current = models.IntegerField(verbose_name='当前观看进度(秒)', default=0)
    total_seconds = models.PositiveIntegerField(verbose_name='本次总观看秒数', default=0)


class View1(BaseModel):
    """
    视频播放统计
    """
    video = models.OneToOneField(Video, on_delete=models.CASCADE, related_name='view1_video')
    views = models.IntegerField(verbose_name='总观看次数', default=0)
    viewsp = models.IntegerField(verbose_name='总观看人数', default=0)


class View2(BaseModel):
    """
    某视频-某人的观看记录统计
    """
    create_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='观看人', related_name='view2_user')
    current = models.IntegerField(verbose_name='当前观看进度(秒)', default=0)
    video = models.ForeignKey(Video, verbose_name='点播视频', on_delete=models.CASCADE, related_name='view2_video')
    views = models.IntegerField(verbose_name='总观看次数', default=0)
    total_seconds = models.PositiveIntegerField(verbose_name='总观看秒数', default=0)
    is_completed = models.BooleanField(default=False)

    class Meta:
        unique_together = (
            ('create_by','video'),  # 联合唯一
        )