from tortoise import fields
from tortoise.models import Model
from pydantic import BaseModel
from datetime import datetime
from tortoise import fields
from tortoise.models import Model
from pydantic import BaseModel
from datetime import datetime

class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=30, unique=True, description="帳號")
    password = fields.CharField(max_length=128, description="密碼")
    email = fields.CharField(max_length=128, description="信箱")
    points = fields.IntField(description="點數")
    is_superuser = fields.IntField(description="超級使用者")
    token = fields.CharField(max_length=200)
    is_active = fields.IntField(description="是否已認證")
    create_time = fields.DatetimeField(description="創建時間")

class UserPydantic(BaseModel):
    id: int
    username: str
    password: str
    email: str
    points: int
    is_superuser: int
    token: str
    # position : str
    is_active: int
    class Config:
        orm_mode = True
#學校
class Schools(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100, description="學校名稱")
    longitude = fields.CharField(max_length=100, description="經度")
    latitude = fields.CharField(max_length=100, description="緯度")
    address = fields.CharField(max_length=128,description="地址")
    update_time = fields.DatetimeField(description="更新時間")
    introduction = fields.TextField(description="簡介", null=True)
    email = fields.TextField(description="email", null=True)
    phone = fields.TextField(description="電話", null=True)
    create_user_id = fields.IntField(description="創建使用者ID", null=True)
    teachers =  fields.TextField(description="老師", null=True)
    is_delete = fields.IntField(description="是否刪除")
    is_pass_proposal = fields.IntField(description="是否通過提案")
    principal_user_id = fields.IntField(description="負責人", null=True)

    def show_data(self):
        return {
            "location_id": self.id,
            "location_name": self.name,
            "Lng": self.longitude,
            "Lat": self.latitude,
            "address": self.address,
            "update_time":self.update_time,
            "school_introduction":self.introduction,
            "email":self.email,
            "phone":self.phone,
            "school_create_user_id" :self.create_user_id,
            "teachers_list" : self.teachers,
            "is_delete" : self.is_delete,
            "is_pass_proposal" : self.is_pass_proposal
        }

class Group_name(Model):
    id =  fields.IntField(pk=True)
    group_name = fields.CharField(max_length=45, description="學群名稱")
    describe = fields.TextField(description="學群介紹", null=True)
    
class Class_name(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100, description="課程名稱")
    school_id = fields.IntField(description="學校ID")
    category = fields.CharField(max_length=45, description="分類", null=True)
    introduction = fields.TextField(description="簡介", null=True)
    organizer = fields.CharField(max_length=200, description="主辦單位", null=True)
    cover_img = fields.CharField(max_length=255, description="封面圖片", null=True)
    group_id = fields.IntField(description="學群")
    group_sort = fields.CharField(max_length=45, description="學群細分")
    special_class_list_name = fields.CharField(max_length=45, description="特殊表格", null=True)
    recommend = fields.IntField(description="是否在首頁")
    is_inner = fields.IntField(description="是否是內課")
    is_check = fields.IntField(description="是否確認")
    create_user_id = fields.IntField(description="創建使用者ID", null=True)
    create_time = fields.DatetimeField(description="創建時間", null=True)
    is_delete = fields.IntField(description="是否刪除")
    is_record_point = fields.IntField(description="是否已經計算過點數", null=True)
    teachers_resume = fields.TextField(description="老師簡麗", null=True)
    encode = fields.CharField(max_length=100, description="課程編碼", null=True)

    def show_data(self):
        return {
            "class_name_id": self.id,
            "name": self.name,
            "category": self.category,
            "introduction": self.introduction,
            "organizer": self.organizer,
            "group_id": self.group_id,
            "cover_img": self.cover_img,
            "group_sort":self.group_sort,
            "recommend" : self.recommend,
            "is_inner" : self.is_inner,
            "is_check" :self.is_check,
            "special_class_list_name":self.special_class_list_name,
            "create_user_id" :self.create_user_id,
            "create_time" : self.create_time,
            "is_delete" : self.is_delete,
            "is_record_point" : self.is_record_point,
            "teachers_resume" : self.teachers_resume,
            "encode" : self.encode
        }


class Class_list(Model):
    id = fields.IntField(pk=True)
    name_id = fields.IntField(description="課程名稱ID")
    event = fields.CharField(max_length=45, description="場次", null=True)
    start_time = fields.DatetimeField(description="開始時間", null=True)
    end_time = fields.DatetimeField(description="結束時間", null=True)
    contact = fields.CharField(max_length=255, description="聯絡方式", null=True)
    lecturer = fields.CharField(max_length=255, description="講師", null=True)
    location = fields.CharField(max_length=255, description="地點詳情", null=True)
    content = fields.TextField(description="內容", null=True)
    URL = fields.TextField(description="連結網址", null=True)
    people = fields.CharField(max_length=255, description="對象", null=True)
    fee_method = fields.CharField(max_length=255, description="收費方式", null=True)
    registration_way = fields.CharField(max_length=255, description="報名方式", null=True)
    remark = fields.TextField(description="備註", null=True)
    ATM_address = fields.TextField(description="匯款帳號", null=True)
    fee_payment = fields.CharField(max_length=45, description="收費方式", null=True)
    create_user_id = fields.IntField(description="創建使用者ID", null=True)
    event_create_time = fields.DatetimeField(description="創建時間", null=True)
    files = fields.TextField(description="附件", null=True)

    def show_data(self):
        return {
            "event_id": self.id,
            "name_id": self.name_id,
            "event": self.event,
            "start_time": self.start_time,
            "end_time": self.end_time,
            "location": self.location,
            "lecturer": self.lecturer,
            "contact": self.contact,
            "content": self.content,
            "URL": self.URL,
            "people": self.people,
            "fee_method": self.fee_method,
            "registration_way": self.registration_way,
            "remark": self.remark,
            "ATM_address":self.ATM_address,
            "fee_payment" :self.fee_payment,
            "create_user_id" :self.create_user_id,
            "event_create_time" : self.event_create_time,
            "files" : self.files
        }


class Class_detail(Model):
    id = fields.IntField(pk=True)
    class_list_id = fields.IntField(description="課程場次ID")
    start_time = fields.DatetimeField(description="開始時間")
    end_time = fields.DatetimeField(description="結束時間")
    sessions = fields.IntField(description="堂數")
    content = fields.TextField(description="內容", null=True)
    hour = fields.IntField(description="時數")

class Registration(Model):
    id = fields.IntField(pk=True)
    event_id = fields.IntField(description="課程ID")
    user_id = fields.IntField(description="使用者ID")
    reg_confirm = fields.IntField(description="報名確認(1:報名成功 0:單純報名)")
    is_del = fields.IntField(description="是否取消(1:yes ,0:no)")
    is_attend = fields.IntField(description="是否出席(1:yes ,0:no)")
    payment_status = fields.IntField(description="是否付款(1:yes ,0:no)")
    five_digits = fields.CharField(max_length=200, description="匯款末五碼",null=True)
    create_time = fields.DatetimeField(description="創建時間")


class News(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=200, description="標題")
    category = fields.CharField(max_length=45, description="類別", null=True)
    create_time = fields.DatetimeField(description="發布時間")
    click_time = fields.IntField(description="點擊次數", null=True)
    content = fields.TextField(description="內容", null=True)
    files = fields.TextField(description="附加檔案", null=True)
    URL = fields.TextField(description="外部連結", null=True)
    tags = fields.TextField(description="標籤", null=True)
    cover_img = fields.CharField(max_length=255, description="封面圖片", null=True)

class Favorite_course(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="使用者ID")
    class_name_id = fields.IntField(description="課程ID")
    time_stemp = fields.DatetimeField(description="時間")

class Article_list(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=200, description="標題")
    school_id = fields.IntField(description="學校ID", null=True)
    group_id = fields.IntField(description="學群", null=True)
    group_sort = fields.CharField(max_length=45, description="學群細分", null=True)
    create_user_id = fields.IntField(description="創建使用者ID", null=True)
    create_time = fields.DatetimeField(description="創建時間", null=True)
    latest_update_user_id = fields.IntField(description="最新更新使用者ID", null=True)
    latest_update_time = fields.DatetimeField(description="最新更新時間", null=True)
    tags = fields.TextField(description="標籤", null=True)
    category = fields.CharField(max_length=45, description="類別", null=True)
    depiction = fields.TextField(description="文章描述", null=True)
    cover_img = fields.TextField( description="封面圖片", null=True)
    vedio_url = fields.TextField( description="影片連結", null=True)
    click_time = fields.IntField(description="點擊次數", null=True)
    content = fields.TextField(description="內容", null=True)
    is_del = fields.IntField(description="是否刪除")
    files = fields.TextField(description="附件", null=True)
    url = fields.TextField(description="文章連結", null=True)
    recommend = fields.IntField(description="是否在首頁")
    writer = fields.CharField(max_length=200, description="著作", null=True)
    publish = fields.CharField(max_length=200, description="出版社", null=True)
    publish_date = fields.DatetimeField(description="出版時間", null=True)
    language = fields.CharField(max_length=200, description="語言", null=True)
    buy_way = fields.TextField(description="購買方式", null=True)


class Online_course(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=45, description="標題")
    category = fields.CharField(max_length=45, description="類別", null=True)
    create_time = fields.DatetimeField(description="發布時間")
    click_time = fields.IntField(description="點擊次數", null=True)
    content = fields.TextField(description="發布時間", null=True)
    video_url = fields.TextField(description="影片連結")
    group_id = fields.IntField(description="學群", null=True)
    cover_img = fields.TextField(description="封面圖片", null=True)
    org = fields.CharField(max_length=255, description="課程來源", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "title": self.title,
            "category": self.category,
            "create_time": self.create_time,
            "click_time": self.click_time,
            "content": self.content,
            "video_url": self.video_url,
            "group_id": self.group_id,
            "cover_img": self.cover_img,
            "org": self.org
        }

class Guidance_group(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=125, description="協會(團體)名稱")
    contact_person = fields.CharField(max_length=125, description="聯絡人")
    contact_phone = fields.CharField(max_length=125, description="聯絡電話")
    line = fields.IntField(description="LINE (0:沒有、1:有)")
    address = fields.TextField(description="地址")
    email = fields.CharField(max_length=125, description="信箱")
    information = fields.TextField(description="開課資訊")
    request = fields.TextField(description="需求")
    schedule = fields.CharField(max_length=45, description="處理進度")
    result = fields.CharField(max_length=125, description="處理結果")
    person = fields.CharField(max_length=45, description="輔導人員")
    remark = fields.TextField(description="備註")
    create_time = fields.DatetimeField(description="創建時間")
    
class User_information(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="使用者ID")
    name = fields.CharField(max_length=45, description="姓名")
    birthday = fields.DateField(description="生日")
    gender = fields.CharField(max_length=45, description="性別")
    phone = fields.CharField(max_length=45, description="電話")
    address = fields.TextField(description="地址")
    is_default = fields.IntField(description="是否為預設")
    position = fields.JSONField(max_length=200,description="登入身分")
    identity = fields.TextField(description="身分別", null=True)

class Class_date(Model):
    id = fields.IntField(pk=True)
    class_list_id = fields.IntField(description="場次ID")
    registration_start = fields.DatetimeField(description="報名時間開始", null=True)
    registration_end = fields.DatetimeField(description="報名時間結束", null=True)
    number_limit = fields.IntField(description="名額", null=True)
    amount_left = fields.IntField(description="剩餘名額", null=True)
    number_minimum = fields.IntField(description="最低人數", null=True)

class Attend_record(Model):
    id = fields.IntField(pk=True)
    class_name_id = fields.IntField(description="課程ID")
    class_event_id = fields.IntField(description="場次ID")
    class_detail_id = fields.IntField(description="課堂ID")
    user_id = fields.IntField(description="使用者ID")
    is_attend = fields.IntField(description="是否已出席(1:是、0:否)")

class One_day_class(Model):
    id = fields.IntField(pk=True)
    name_id = fields.IntField(description="課程名稱")
    teacher = fields.CharField(max_length=100, description="老師", null=True)
    contact = fields.CharField(max_length=100, description="聯絡方式", null=True)
    start_time = fields.DatetimeField(description="開始時間", null=True)
    end_time = fields.DatetimeField(description="結束時間", null=True)
    reg_deadline = fields.DatetimeField(description="報名結束時間", null=True)
    remark = fields.TextField(description="備註", null=True)
    people = fields.CharField(max_length=255, description="對象", null=True)
    way = fields.CharField(max_length=45, description="上課方式", null=True)
    fee_method = fields.TextField(description="收費方式", null=True)
    material = fields.TextField(description="材料", null=True)
    tools = fields.TextField(description="材料", null=True)
    number_limit = fields.TextField(description="人數限制", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "name_id": self.name_id,
            "teacher": self.teacher,
            "contact": self.contact,
            "start_time": self.start_time,
            "end_time": self.end_time,
            "reg_deadline": self.reg_deadline,
            "remark": self.remark,
            "people": self.people,
            "way": self.way,
            "material": self.material,
            "tools": self.tools,
            "number_limit": self.number_limit
        }
    
class User_resume(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="使用者編號", null=True)
    teacher_name = fields.CharField(max_length=45,description="老師名字")
    work_type = fields.CharField(max_length=45, description="工作性質", null=True)
    experience = fields.CharField(max_length=100, description="教學經驗", null=True)
    expertise = fields.TextField(description="專業工藝技能", null=True)
    license = fields.TextField(description="相關證照", null=True)
    media = fields.TextField(description="社群媒體", null=True)
    imgs = fields.TextField(description="作品集", null=True)
    introduction = fields.TextField(description="自我介紹", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "user_id": self.user_id,
            "teacher_name": self.teacher_name,
            "work_type": self.work_type,
            "experience": self.experience,
            "expertise": self.expertise,
            "license": self.license,
            "media": self.media,
            "imgs": self.imgs,
            "introduction": self.introduction
        }
    
class Tgc_pic(Model):
    id = fields.IntField(pk=True)
    pic_name = fields.TextField(description="照片名稱", null=True)
    pic_url = fields.TextField(description="照片連結", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "pic_name": self.pic_name,
            "pic_url": self.pic_url
        }
    
class Tgc_report(Model):
    id = fields.IntField(pk=True)
    title = fields.CharField(max_length=100,description="標題", null=True)
    create_time = fields.DatetimeField(description="創建時間", null=True)
    url = fields.TextField(description="連結", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "title": self.title,
            "create_time": self.create_time,
            "url": self.url
        }
    
class Outter_class_list(Model):
    id = fields.IntField(pk=True)
    name_id = fields.IntField(description="課程名稱")
    start_time = fields.DatetimeField(description="開始時間", null=True)
    end_time = fields.DatetimeField(description="結束時間", null=True)
    imgs = fields.TextField(description="圖片", null=True)
    price = fields.CharField(max_length=45, description="價錢", null=True)
    URL = fields.TextField(description="連結", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "name_id": self.name_id,
            "start_time": self.start_time,
            "end_time": self.end_time,
            "imgs": self.imgs,
            "price": self.price,
            "URL": self.URL
        }
    
class User_point(Model):
    user_id = fields.IntField(pk=True)
    hours =  fields.FloatField(description="累積時數")
    points = fields.IntField(description="累積點數")

    def show_data(self):
        return {
            "user_id" : self.user_id,
            "hours": self.hours,
            "points": self.points
        }
    
class Point_exchange_record(Model):
    id = fields.IntField(pk=True)
    user_id = fields.IntField(description="使用者")
    point_exchange = fields.IntField(description="兌換點數")
    time_stemp = fields.DatetimeField(description="兌換時間", null=True)

    def show_data(self):
        return {
            "id" : self.id,
            "user_id" : self.user_id,
            "points_exchange": self.point_exchange,
            "time_stemp": self.time_stemp
        }
    
class Proposal(Model):
    id = fields.IntField(pk=True)
    class_name = fields.CharField(max_length=100, description="課程名稱")
    school_id = fields.IntField(description="學校ID")
    category = fields.CharField(max_length=45, description="分類", null=True)
    introduction = fields.TextField(description="簡介", null=True)
    organizer = fields.CharField(max_length=200, description="主辦單位", null=True)
    cover_img = fields.TextField(description="封面圖片", null=True)
    create_time = fields.DatetimeField(description="創建時間", null=True)
    fee_method = fields.TextField(description="價錢", null=True)
    number_limit = fields.IntField(description="人數限制", null=True)
    number_minimum =  fields.IntField(description="最低人數", null=True)
    people = fields.TextField(description="對象", null=True)
    files = fields.TextField(description="PPT", null=True)

    def show_data(self):
        return {
            "proposal_id": self.id,
            "class_name": self.class_name,
            "school_id": self.school_id,
            "category": self.category,
            "introduction": self.introduction,
            "cover_img": self.cover_img,
            "organizer":self.organizer,
            "number_minimum" : self.number_minimum,
            "fee_method" : self.fee_method,
            "number_limit" :self.number_limit,
            "people":self.people,
            "files" :self.files,
            "create_time" : self.create_time
        }