import VectorType from '../enum/VectorType.js'
import BgImage from '../Geometry/BgImage.js'
import { mathUtil } from '../MathUtil.js'
import { floorplanService } from './FloorplanService'
import Constant from '../Constant'

export default class BgImageService {
    constructor() { 
        this.url = null;
    }

    setBgImageUrl(url){
        this.url = url;
    }

    async createBgImage(center,vectorId) {
        const bgImage = new BgImage(this.url, center,vectorId)
        if(this.url){
            const imageData = await floorplanService.loadImageData(this.url)
            bgImage.setImageData(imageData)
        }

        floorplanService.addBgImage(bgImage)
        this.url = null;
        return bgImage
    }

    deleteBgImage(bgImageId) {
        floorplanService.deleteBgImage(bgImageId)
    }

    setBgImageInfo(bgImageInfo) {
        let bgImage = floorplanService.getBgImage(bgImageInfo.vectorId)
        bgImage.vectorId = bgImageInfo.vectorId
        bgImage.url = bgImageInfo.url
        bgImage.scale = bgImageInfo.scale
        bgImage.center = JSON.parse(JSON.stringify(bgImageInfo.center))
    }
}

const bgImageService = new BgImageService()
export { bgImageService }