create table account_detail
(
    id          bigint auto_increment
        primary key,
    ssid        varchar(64) not null comment 'ssid',
    type        int         null comment '类型 0：赠送 1：每日领取 100：扣除 101：使用图生视频 102：使用文生视频 103：使用一键成片 104：使用绘画 200：退款',
    value       bigint      null comment '值',
    create_time datetime    null comment '创建时间'
);

create index idx_create_time
    on account_detail (create_time);

create index idx_ssid
    on account_detail (ssid);


create table complaint
(
    id          bigint auto_increment
        primary key,
    ssid        varchar(64)   not null,
    device_id   varchar(64)   null,
    uid         bigint        null,
    reason      varchar(255)  null,
    content     varchar(5000) null,
    phone       varchar(64)   null,
    images      varchar(1000) null,
    create_time datetime      null,
    update_time datetime      null,
    status      int default 0 null
);


create table draw_info
(
    id          varchar(64)   not null
        primary key,
    task_id     varchar(64)   null comment '任务id',
    ssid        varchar(64)   not null comment 'ssid',
    content     varchar(1000) null comment '绘画内容',
    image_url   varchar(255)  null comment '图片地址',
    status      int default 0 null comment '状态',
    is_deleted  int default 0 null comment '是否被删除',
    create_time datetime      null comment '创建时间',
    update_time datetime      null comment '更新时间'
);

create index idx_create_time
    on draw_info (create_time);

create index idx_ssid
    on draw_info (ssid);


create table draw_task_log
(
    task_id     varchar(64)   not null
        primary key,
    user_id     varchar(64)   not null,
    model       varchar(255)  null,
    content     varchar(1000) null,
    prompt      varchar(5000) null,
    start_time  datetime      null,
    send_time   datetime      null,
    handle_time datetime      null,
    upload_time datetime      null,
    check_time  datetime      null,
    finish_time datetime      null,
    fail_reason varchar(5000) null
);


create table member_auth
(
    id              bigint auto_increment
        primary key,
    ssid            varchar(64)      not null,
    out_trade_no    varchar(64)      null,
    auth            varchar(255)     not null,
    auth_value      bigint default 0 not null,
    start_timestamp bigint           not null,
    end_timestamp   bigint           not null,
    create_time     datetime         not null,
    update_time     datetime         not null
);

create index idx_auth
    on member_auth (auth);

create index idx_out_trade_no
    on member_auth (out_trade_no);

create index ssid_index
    on member_auth (ssid);


create table order_info
(
    id              bigint auto_increment
        primary key,
    out_trade_no    varchar(128) not null,
    user_id         varchar(64)  null,
    ssid            varchar(64)  not null,
    device_id       varchar(64)  not null,
    phone           varchar(64)  null,
    item_id         bigint       not null,
    item_name       varchar(255) not null,
    original_amount bigint       not null,
    amount          bigint       not null,
    app_platform    int          not null,
    package_name    varchar(255) not null,
    channel_name    varchar(255) null,
    ip              varchar(255) null,
    create_time     datetime     not null,
    update_time     datetime     not null,
    pay_status      int          not null comment '-- 0:已创建 1:未支付 2:已支付 3:已关闭 4:已退款',
    status          int          not null,
    constraint out_trade_no_index
        unique (out_trade_no)
);


create table risk_check_log
(
    id               int auto_increment
        primary key,
    user_id          varchar(64) null,
    phone            varchar(32) null,
    source_type      varchar(16) null,
    content_type     varchar(16) null,
    content          mediumtext  null,
    response_code    varchar(16) null,
    response_message varchar(64) null,
    risk_level       varchar(32) null,
    risk_level_msg   varchar(64) null,
    create_time      datetime    null,
    ip               varchar(64) null,
    data             mediumtext  null
);


create table upload_log
(
    id                bigint auto_increment
        primary key,
    ssid              varchar(64)   not null,
    cdn_host          varchar(255)  not null,
    file_key          varchar(1000) not null,
    original_filename varchar(255)  null,
    ip                varchar(255)  null,
    create_time       datetime      not null,
    update_time       datetime      not null,
    status            int           not null
);

create index ssid_index
    on upload_log (ssid);


create table user_auth
(
    id              bigint auto_increment
        primary key,
    ssid            varchar(64) not null comment 'ssid',
    free_chat_time  bigint      null comment '已使用的免费聊天次数',
    free_draw_time  bigint      null comment '已使用的免费绘画次数',
    free_video_time bigint      null comment '已使用的免费视频次数',
    free_tool_time  bigint      null comment '已使用的免费工具次数',
    create_time     datetime    null,
    update_time     datetime    null
);

create index idx_ssid
    on user_auth (ssid);


create table video_generate_log
(
    task_id     varchar(64)   not null
        primary key,
    user_id     varchar(64)   null,
    ssid        varchar(64)   null,
    device_id   varchar(64)   null,
    phone       varchar(32)   null,
    prompt      varchar(5000) null,
    video_id    varchar(64)   null,
    video_type  varchar(255)  null,
    start_time  datetime      null,
    send_time   datetime      null,
    handle_time datetime      null,
    finish_time datetime      null,
    fail_reason varchar(5000) null,
    source      varchar(64)   null
);

create index idx_ssid
    on video_generate_log (ssid);

create index idx_start_time
    on video_generate_log (start_time);


create table video_info
(
    id               varchar(64)   not null
        primary key,
    task_id          varchar(64)   null comment '任务id',
    ssid             varchar(64)   not null comment 'ssid',
    video_type       varchar(255)  null comment '类型',
    prompt           varchar(5000) null comment '提示词',
    name             varchar(255)  null comment '视频名称',
    cover_url        varchar(255)  null comment '视频封面图片',
    origin_cover_url varchar(255)  null comment '原始封面',
    video_url        varchar(255)  null comment '视频地址',
    origin_video_url varchar(255)  null comment '原始视频地址',
    image_url        varchar(255)  null comment '开始图片（首帧）',
    tail_image_url   varchar(255)  null comment '结束图片（尾帧）',
    read_status      int default 0 null comment '已读状态',
    status           int default 0 null comment '视频状态',
    is_deleted       int default 0 null comment '是否被删除 0：未删除 1：用户删除 2：系统删除',
    voice_id         int           null comment '音色id',
    bgm_id           int           null comment '背景音乐id',
    tool_id          int           null comment '工具模板id',
    subtitle         int default 0 null comment '是否添加字幕 0：否 1：是',
    create_time      datetime      null comment '创建时间',
    update_time      datetime      null comment '更新时间'
);

create index idx_create_time
    on video_info (create_time);

create index idx_ssid
    on video_info (ssid);

create index idx_task_id
    on video_info (task_id);