export interface BackendResponse<T> {
    success: boolean
    status: number
    error: string
    ratelimit: {
        remains: number
        limit: number
        reset: number
    }
    text: string
    json: T
}

export interface BackendLimitReportOption {
    id: number
    title: string
    description: string
}

export interface BackendLimitType<T = undefined> {
    normalizers: {
        match: string
        replace: string
        comment: string
    }[]
    matcher: string
    max_length: number
    min_length: number
    values: T
}

export interface BackendLimit {
    upload: {
        input_width_min: number
        input_height_min: number
        video_width_max: number
        video_height_max: number
        image_width_max: number
        image_height_max: number
        duration: number
        filesize: number
        mime_types: string[]
    }
    title: BackendLimitType
    tag: BackendLimitType
    comment: BackendLimitType
    report: BackendLimitType<BackendLimitReportOption>
}

export interface BackendChallenge {
    nonce: string
    difficulty: number
    /** UNIX Timestamp */
    expires: number
}

export interface BackendTag {
    id: string
    label: string
    usage: number
}

export interface BackendArt {
    id: string
    created: string
    sticker: boolean
    audio: boolean
    framerate: number
    width: number
    height: number
    /** Float 0-1 */
    rating: number
    title: string
    tags: BackendTag[]
}

export type UploadEventType =
    | UploadEventID
    | UploadEventError
    | UploadEventStep
    | UploadEventProgress
    | UploadEventFinish

interface UploadEventID {
    name: 'id'
    data: string
}

interface UploadEventError {
    name: 'error'
    data: {
        code: number
        message: string
    }
}

interface UploadEventStep {
    name: 'step'
    data: {
        id: 'PROBE_QUEUE' | 'PROBE_START' | 'ENCODE_QUEUE' | 'ENCODE_START' | 'SERVER_FINALIZE'
        message: string
    }
}

interface UploadEventProgress {
    name: 'progress'
    data: {
        /** float string (e.g. 45.12) */
        percent: string
    }
}

interface UploadEventFinish {
    name: 'finish'
    data: {
        id: string
        edit_token: string
    }
}
