-- M4 分镜工作台

CREATE TABLE storyboards (
    id                   BIGINT          NOT NULL PRIMARY KEY,
    project_id           BIGINT          NOT NULL,
    episode_id           BIGINT          NOT NULL,
    tenant_id            BIGINT          NOT NULL,
    sequence_num         INT             NOT NULL DEFAULT 0,
    scene_number         VARCHAR(16),
    short_description    TEXT,
    detailed_description LONGTEXT,
    characters           TEXT,
    dialogues            TEXT,
    camera_direction     VARCHAR(64),
    composition_guide    VARCHAR(64),
    duration_seconds     INT             DEFAULT 5,
    motion_script        TEXT,
    start_frame_prompt   TEXT,
    end_frame_prompt     TEXT,
    notes                TEXT,
    status               VARCHAR(32)     NOT NULL DEFAULT 'draft',
    created_at           DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    updated_at           DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
    INDEX idx_episode_seq (episode_id, sequence_num),
    INDEX idx_project (project_id),
    INDEX idx_tenant (tenant_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE shot_assets (
    id              BIGINT          NOT NULL PRIMARY KEY,
    storyboard_id   BIGINT          NOT NULL,
    tenant_id       BIGINT          NOT NULL,
    asset_type      VARCHAR(32)     NOT NULL,
    tos_key         VARCHAR(512),
    external_url    VARCHAR(1024),
    prompt          TEXT,
    model_provider  VARCHAR(64),
    model_id        VARCHAR(128),
    status          VARCHAR(32)     NOT NULL DEFAULT 'pending',
    is_active       TINYINT(1)      NOT NULL DEFAULT 1,
    created_at      DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    INDEX idx_sb (storyboard_id),
    INDEX idx_sb_type (storyboard_id, asset_type, is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
