from django.db import models
from rbac.models import CommonModel, UserProfile

# Create your models here.
class Course(CommonModel):
    """
    视频课程分类
    """
    name = models.CharField(max_length=200, verbose_name='名称')
    description = models.TextField(verbose_name='课程介绍', null=True, blank=True)
    sort = models.IntegerField(default=1, verbose_name='排序数字')
    create_admin = models.ForeignKey(UserProfile, on_delete=models.SET_NULL, null=True, blank=True, related_name='course_create_admin')

class Video(CommonModel):
    """
    视频
    """
    name = models.CharField(verbose_name='视频名称', max_length=100)
    course = models.ForeignKey(Course, verbose_name='所属课程', on_delete=models.CASCADE)
    description = models.TextField(verbose_name='视频描述', null=True, blank=True)
    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)

class VRecord(CommonModel):

    """
    观看记录
    """
    consumer = models.ForeignKey('crm.consumer', on_delete=models.CASCADE, verbose_name='观看人', related_name='viewrecord_consumer')
    views = models.PositiveIntegerField(verbose_name='观看次数', default=0)
    completed = models.BooleanField(verbose_name='是否观看完成', default=False)
    current = models.PositiveIntegerField(verbose_name='当前观看进度(秒)', default=0)
    video = models.ForeignKey(Video, verbose_name='点播视频', on_delete=models.CASCADE, related_name='record_video')