/**
 * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 */

import { Task } from 'mol-task'
import { RenderObject } from 'mol-gl/render-object';
import { RepresentationProps, Representation, Visual } from '..';
import { VolumeData } from 'mol-model/volume';
import { PickingId } from '../../util/picking';
import { Loci, EmptyLoci } from 'mol-model/loci';
import { MarkerAction } from '../../util/marker-data';
import { DefaultBaseProps } from '../util';

export interface VolumeVisual<P extends RepresentationProps = {}> extends Visual<VolumeData, P> { }

export interface VolumeRepresentation<P extends RepresentationProps = {}> extends Representation<VolumeData, P> { }

export const DefaultVolumeProps = {
    ...DefaultBaseProps
}
export type VolumeProps = typeof DefaultVolumeProps

export function VolumeRepresentation<P extends VolumeProps>(visualCtor: (volumeData: VolumeData) => VolumeVisual<P>): VolumeRepresentation<P> {
    const renderObjects: RenderObject[] = []
    let _volumeData: VolumeData
    let _props: P

    function create(volumeData: VolumeData, props: Partial<P> = {}) {
        _props = Object.assign({}, DefaultVolumeProps, _props, props)
        return Task.create('VolumeRepresentation.create', async ctx => {
            _volumeData = volumeData
            const visual = visualCtor(_volumeData)
            await visual.create(ctx, _volumeData, props)
            renderObjects.push(visual.renderObject)
        });
    }

    function update(props: Partial<P>) {
        return Task.create('VolumeRepresentation.update', async ctx => {})
    }

    return {
        get renderObjects () { return renderObjects },
        get props () { return _props },
        create,
        update,
        getLoci(pickingId: PickingId) {
            // TODO
            return EmptyLoci
        },
        mark(loci: Loci, action: MarkerAction) {
            // TODO
        },
        destroy() {
            // TODO
        }
    }
}