from django.db import models


# Create your models here.
class BabyUser(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    user_id = models.CharField(default='', max_length=32, verbose_name='关联用户id')
    nick_name = models.CharField(default='', max_length=20, verbose_name='昵称')
    sex = models.SmallIntegerField(default=0, verbose_name='性别')  # 0：女 1：男
    birthday = models.IntegerField(default=0, verbose_name='生日')
    icon_url = models.TextField(default='', verbose_name='头像地址')
    device_id = models.CharField(default='', max_length=32, verbose_name='关联设备')
    serial_no = models.CharField(default='', max_length=32, verbose_name='关联序列号')
    is_default = models.BooleanField(default=False, verbose_name='是否默认')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'baby_user'
        verbose_name = '宝宝用户表'
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class FeedType(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    name = models.CharField(default='', max_length=10, verbose_name='名称')
    # 1：母乳亲喂 2：母乳瓶喂 3：奶粉 4：辅食 5：换尿布 6：身高体重 7：户外活动 8：育儿日记 9：自定义 10:体温
    sort = models.IntegerField(default=0, verbose_name='排序')
    icon_url = models.TextField(default='', verbose_name='图标地址')
    is_show = models.BooleanField(default=True, verbose_name='是否展示')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'feed_type'
        verbose_name = '喂养类型表'
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class FeedDiary(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    baby_id = models.IntegerField(default=0, verbose_name='关联宝宝id')
    feed_type = models.ForeignKey(FeedType, to_field='id', on_delete=models.CASCADE, default='', verbose_name='喂养类型')
    # 1：母乳亲喂 2：母乳瓶喂 3：奶粉 4：辅食 5：换尿布 6：身高体重 7：户外活动 8：育儿日记 9：自定义
    feed_content = models.JSONField(null=True, verbose_name='事件内容')
    # 当类型为5时，sub_event_type为 1:嘘嘘 2:臭臭 3：嘘嘘+臭臭 4：干爽
    date_time = models.IntegerField(default=0, verbose_name='事件时间')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'feed_diary'
        verbose_name = '喂养日记表'
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class AlbumTitle(models.Model):
    id = models.AutoField(primary_key=True)
    album_title = models.TextField(blank=True, default='', verbose_name='相册标题')
    lang = models.CharField(default='', max_length=10, verbose_name='语言')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'album_title'
        verbose_name = '时光相册默认标题表'
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class TimeAlbum(models.Model):
    id = models.AutoField(primary_key=True)
    device_id = models.CharField(default='', max_length=32, verbose_name='关联设备',  db_index=True)
    album_date = models.IntegerField(default=0, verbose_name='相册日期', db_index=True)
    album_title = models.TextField(default=0, verbose_name='相册标题')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = 'time_album'
        verbose_name = '设备时光相册表'
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class AlbumMedia(models.Model):
    id = models.AutoField(primary_key=True)
    time_album_id = models.IntegerField(default=0, verbose_name=u'时光相册表id', db_index=True)
    # 这三个字段组成存储桶的访问链接
    device_id = models.CharField(default='', max_length=32, verbose_name='关联设备', db_index=True)
    channel = models.IntegerField(default=1, verbose_name='通道')
    event_time = models.IntegerField(default=0, verbose_name='事件时间')
    # 0表示隐藏 1表示显示 2表示被添加为日记
    status = models.SmallIntegerField(default=1, verbose_name='状态')
    # 1: 阿里云, 2: AWS, 3: oci美国凤凰城, 4: oci英国伦敦, 5: 华为云
    storage_location = models.SmallIntegerField(default=0, verbose_name='存储位置')
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = "album_media"
        verbose_name = "相册媒体表"
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class TimeDiary(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.CharField(default='', max_length=32, verbose_name='关联用户id', db_index=True)
    diary_date = models.IntegerField(default=0, verbose_name='日记日期', db_index=True)
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = "time_diary"
        verbose_name = "用户时光日记表"
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class DiaryAlbumMediaRelation(models.Model):
    id = models.AutoField(primary_key=True)
    diary = models.ForeignKey(TimeDiary, on_delete=models.CASCADE, db_index=True, db_constraint=False, verbose_name="日记")
    album_media = models.ForeignKey(AlbumMedia, on_delete=models.CASCADE, db_index=True, db_constraint=False, verbose_name="相册媒体")
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = "diary_album_media_relation"
        verbose_name = "日记与相册媒体关联表"
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'
        unique_together = ('diary', 'album_media')  # 防止重复关联


class BabyGrowthStandard(models.Model):
    age_min = models.IntegerField(verbose_name="最小年龄（天）", help_text="单位：天")
    age_max = models.IntegerField(verbose_name="最大年龄（天）", help_text="单位：天")
    gender = models.IntegerField(default=0, verbose_name="性别")
    height_min = models.FloatField(verbose_name="最小身高 (cm)")
    height_max = models.FloatField(verbose_name="最大身高 (cm)")
    weight_min = models.FloatField(verbose_name="最小体重 (kg)")
    weight_max = models.FloatField(verbose_name="最大体重 (kg)")
    head_circumference_min = models.FloatField(verbose_name="最小头围 (cm)")
    head_circumference_max = models.FloatField(verbose_name="最大头围 (cm)")
    created_time = models.IntegerField(default=0, verbose_name='创建时间')
    updated_time = models.IntegerField(default=0, verbose_name='更新时间')

    class Meta:
        db_table = "baby_growth_standard"
        verbose_name = "婴儿成长标准表"
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'


class DevelopmentalPoints(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='自增id')
    month = models.CharField(default='', max_length=32, verbose_name='月龄')
    title = models.CharField(default='', max_length=32, verbose_name='标题')
    weight = models.CharField(default='', max_length=32, verbose_name='体重')
    height = models.CharField(default='', max_length=32, verbose_name='身高')
    head_circumference = models.CharField(default='', max_length=32, verbose_name='头围')
    content = models.TextField(default='', verbose_name='内容')

    class Meta:
        db_table = "developmental_points"
        verbose_name = "发育要点"
        verbose_name_plural = verbose_name
        app_label = 'Roomumy'
