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(500)  not null,
    phone       varchar(255)  null,
    images      varchar(1000) null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int           not null
);

create table fox_accompaniment_generate_log
(
    task_id     varchar(100)  not null
        primary key,
    user_id     varchar(100)  not null,
    start_time  datetime      null comment '创建任务日志',
    handle_time datetime      null comment '任务处理时间',
    finish_time datetime      null comment '完成时间',
    fail_reason varchar(5000) null comment '失败原因',
    status      tinyint       null comment '状态',
    song_id     varchar(100)  not null comment '歌曲id',
    send_time   datetime      null comment '发送到redis队列时间'
);

create index start_time_index
    on fox_accompaniment_generate_log (start_time);

create table fox_account
(
    id                 bigint auto_increment
        primary key,
    account            varchar(255)  null,
    endpoint           varchar(255)  null,
    api_key            varchar(255)  not null,
    expired            int default 0 not null,
    songs_left         int default 0 not null,
    points_update_time datetime      null,
    status             int default 0 not null
);

create table fox_song
(
    song_id             varchar(64)              not null
        primary key,
    video_url           varchar(255)             null,
    audio_url           varchar(255)             null,
    image_url           varchar(255)             null,
    image_large_url     varchar(255)             null,
    model_name          varchar(255)             null,
    user_id             varchar(64)              null,
    status              varchar(64)              null,
    title               varchar(255)             null,
    meta_tags           varchar(255)             null,
    meta_prompt         varchar(5000) default '' null,
    meta_duration       double        default 0  null,
    meta_error_msg      varchar(255)  default '' null,
    meta_error_type     varchar(255)             null,
    meta_history        varchar(1000)            null,
    meta_concat_history varchar(1000)            null,
    meta_type           varchar(64)              null,
    created_time        datetime                 not null,
    source              varchar(64)              null
);

create index created_time_index
    on fox_song (created_time);

create table fox_song_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,
    custom       int           null,
    tags         varchar(1000) null,
    instrumental int default 0 null,
    title        varchar(1000) null,
    description  varchar(1000) null,
    song_id      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 ssid_index
    on fox_song_generate_log (ssid);

create index start_time_index
    on fox_song_generate_log (start_time);

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_out_trade_no
    on member_auth (out_trade_no);

create index ssid_index
    on member_auth (ssid);

create table mv_favorite
(
    id          bigint auto_increment
        primary key,
    ssid        varchar(64) not null,
    mv_id       varchar(64) not null,
    create_time datetime    not null
);

create index ssid_index
    on mv_favorite (ssid);

create index ssid_mv_id_index
    on mv_favorite (ssid, mv_id);

create table mv_generate_log
(
    task_id            varchar(64)   not null
        primary key,
    ssid               varchar(64)   null,
    device_id          varchar(64)   null,
    phone              varchar(32)   null,
    mv_id              varchar(64)   null,
    song_id            varchar(64)   null,
    audio_url          varchar(255)  null,
    orientation        varchar(64)   null,
    paragraph_content  varchar(5000) null,
    image_desc_content varchar(5000) null,
    start_time         datetime      null,
    send_time          datetime      null,
    handle_time        datetime      null,
    finish_time        datetime      null,
    fail_reason        varchar(2000) null
);

create table mv_info
(
    id                     varchar(64)              not null
        primary key,
    mv_type                varchar(64) default 'mv' not null,
    task_id                varchar(64)              null,
    ssid                   varchar(64)              not null,
    title                  varchar(255)             null,
    tags                   varchar(1000)            null,
    description            varchar(1000)            null,
    lyrics                 varchar(10000)           null,
    video_url              varchar(255)             null,
    origin_video_url       varchar(255)             null,
    audio_url              varchar(255)             null,
    origin_audio_url       varchar(255)             null,
    image_url              varchar(255)             null,
    origin_image_url       varchar(255)             null,
    image_large_url        varchar(255)             null,
    origin_image_large_url varchar(255)             null,
    duration               double                   null,
    play_count             int         default 0    not null,
    upvote_count           int         default 0    not null,
    status                 int         default 0    not null,
    timeout_at             datetime                 null,
    read_status            int         default 0    not null,
    create_time            datetime                 not null,
    update_time            datetime                 null,
    nickname               varchar(255)             null,
    head_image_url         varchar(255)             null,
    orientation            varchar(64)              null,
    song_id                varchar(64)              null,
    subtitles_json         json                     null,
    photos_json            json                     null,
    name                   varchar(255)             null,
    template_mv_id         varchar(64)              null,
    generate_request       json                     null,
    is_deleted             int         default 0    not null
);

create index ssid_index
    on mv_info (ssid);

create table order_info
(
    id              bigint auto_increment
        primary key,
    out_trade_no    varchar(128) not 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
);

create index out_trade_no_index
    on order_info (out_trade_no);

create table play_praise
(
    id          varchar(50)                        not null
        primary key,
    user_id     varchar(50)                        null comment '用户id',
    play_id     varchar(50)                        null comment '歌单id',
    create_time datetime default CURRENT_TIMESTAMP null comment '创建时间'
)
    comment '歌单点赞表' charset = utf8;

create index user_id_playlist_id_idx
    on play_praise (user_id, play_id);

create table playlist
(
    id                 varchar(64)   not null
        primary key,
    ssid               varchar(64)   not null,
    title              varchar(255)  null,
    description        varchar(255)  null,
    image_url          varchar(255)  null,
    create_time        datetime      not null,
    update_time        datetime      not null,
    status             int default 0 not null,
    amount_praise      int default 0 null comment '点赞数',
    amount_play        int default 0 null comment '播放量',
    default_play_num   int default 0 null comment '默认播放数',
    default_praise_num int default 0 null comment '默认点赞数',
    amount_play_song   int default 0 null comment '实际播放数',
    owner              varchar(20)   null comment '所有者'
);

create index ssid_index
    on playlist (ssid);

create table playlist_ref_song
(
    id          bigint auto_increment
        primary key,
    playlist_id varchar(64) not null,
    song_id     varchar(64) not null,
    create_time datetime    not null
);

create index playlist_id_index
    on playlist_ref_song (playlist_id);

create index song_id_index
    on playlist_ref_song (song_id);

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 index create_time_index
    on risk_check_log (create_time);

create table share_point
(
    id          int auto_increment
        primary key,
    user_id     varchar(50)                        null,
    song_id     varchar(50)                        null,
    share_type  varchar(20)                        null,
    score       int      default 0                 null comment '积分',
    create_time datetime default CURRENT_TIMESTAMP null,
    share_time  date                               null comment '分享时间'
)
    charset = utf8;

create index user_id_idx
    on share_point (user_id);

create table song_info
(
    id                     varchar(64)   not null
        primary key,
    task_id                varchar(64)   null,
    ssid                   varchar(64)   not null,
    title                  varchar(255)  null,
    tags                   varchar(1000) null,
    description            varchar(1000) null,
    lyrics                 varchar(8000) null,
    video_url              varchar(255)  null,
    origin_video_url       varchar(255)  null,
    audio_url              varchar(255)  null,
    origin_audio_url       varchar(255)  null,
    image_url              varchar(255)  null,
    origin_image_url       varchar(255)  null,
    image_large_url        varchar(255)  null,
    origin_image_large_url varchar(255)  null,
    duration               double(11, 2) null,
    play_count             int default 0 not null,
    upvote_count           int default 0 not null,
    status                 int           not null,
    create_time            datetime      not null,
    is_deleted             int default 0 not null,
    meta_type              varchar(64)   null,
    meta_source            varchar(64)   null,
    meta_history           varchar(1000) null,
    meta_concat_history    varchar(1000) null,
    amount_praise          int default 0 null comment '点赞数',
    amount_share           int default 0 null comment '分享数',
    amount_play            int default 0 null comment '播放数',
    source                 varchar(64)   null
);

create index create_time_index
    on song_info (create_time);

create index query_index
    on song_info (ssid, status, is_deleted, create_time);

create index ssid_index
    on song_info (ssid);

create index task_id_index
    on song_info (task_id);

create table song_praise
(
    id          varchar(50)                        not null
        primary key,
    user_id     varchar(50)                        null comment '用户id',
    song_id     varchar(50)                        null comment '歌曲id',
    create_time datetime default CURRENT_TIMESTAMP null comment '创建时间'
)
    comment '歌曲点赞表' charset = utf8;

create index user_id_song_id_idx
    on song_praise (user_id, song_id);

create table suno_account
(
    id                 bigint auto_increment
        primary key,
    account            varchar(255)  null,
    endpoint           varchar(255)  null,
    cookie             varchar(5000) not null,
    cookie_update_time datetime      null,
    expired            int default 0 not null,
    credit             int default 0 not null,
    credit_update_time datetime      null,
    status             int default 0 not null
);

create table suno_song
(
    id                  varchar(64)   not null
        primary key,
    video_url           varchar(255)  null,
    audio_url           varchar(255)  null,
    image_url           varchar(255)  null,
    image_large_url     varchar(255)  null,
    major_model_version varchar(64)   null,
    model_name          varchar(255)  null,
    metadata            json          null,
    is_liked            int default 0 not null,
    user_id             varchar(64)   null,
    is_trashed          int default 0 not null,
    reaction            json          null,
    created_at          varchar(32)   null,
    status              varchar(64)   null,
    title               varchar(255)  null,
    play_count          int default 0 not null,
    upvote_count        int default 0 not null,
    is_public           int default 0 not null
);

create table suno_song_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,
    custom       int           null,
    tags         varchar(1000) null,
    instrumental int default 0 null,
    title        varchar(1000) null,
    description  varchar(1000) null,
    suno_song_id varchar(64)   null,
    start_time   datetime      null,
    send_time    datetime      null,
    handle_time  datetime      null,
    finish_time  datetime      null,
    fail_reason  varchar(5000) 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);

