//
//  TSTextGeneralPicVM.swift
//  AIRingtone
//
//  Created by 100Years on 2025/3/4.
//

import Alamofire
import ObjectMapper

let kRandomTextToPicArray:[String] = [
    "Ultra-detailed northern lights over a glacial lake, mirrored reflections with vibrant turquoise and magenta hues, surreal celestial atmosphere, digital painting style with soft glow effects.",
    "Neon-lit cyberpunk night market in a rainy Asian metropolis, holographic food stalls and floating drones, teal-orange color grading, retro-futuristic architecture with glowing Kanji signs",
    "Macro photography of rainbow candy landscape with gummy bear mountains, chocolate river and lollipop trees, hyper-realistic textures under golden hour lighting",
    "Traditional Chinese ink painting style phoenix soaring through misty mountain peaks, dynamic black brushstrokes with crimson accents on rice paper texture",
    "Bioluminescent underwater metropolis with glass dome structures, schools of glowing fish weaving through coral skyscrapers, deep-sea blue palette with neon coral highlights",
    "1950s retro sci-fi movie poster style wallpaper featuring a rocket orbiting Saturn, vintage orange-teal color scheme with halftone textures and hand-drawn typography",
    "Minimalist wallpaper with overlapping translucent 3D geometric shapes in gradient pastel colors, clean negative space, soft shadows and metallic accents, 4K abstract design.",
    "Steampunk floating library with brass gears and clockwork mechanisms, leather-bound books flying through amber-lit fog, Victorian-era architecture blended with retro-futurism",
    "Zen rock garden transformed into cosmic landscape, black sand waves surrounding cratered moon-like stones, starry galaxy reflected in miniature, monochromatic with silver foil accents",
    "Futuristic AI core visualization with flowing golden data streams through transparent quantum circuits, dark background with floating holographic equations, cybernetic glow effect"
]

enum TSGennerateType:Int,Equatable{
    case poster = 0     //海报
    case photo  = 1     //头像
}

class TSTextGeneralPicVM {
    
    //选择 prompt 类型组
    lazy var ptpStyleModels: [TSPTPStyleModel] = {
        var ptpStyleModels = [TSPTPStyleModel]()
        if let dataArray = Mapper<TSPTPStyleModel>().mapArray(JSONfile: "photo_to_photo_style.json"){
            ptpStyleModels = dataArray
            
            if let model = dataArray.first {
                selectPromptModel = model //加上默认的选择
            }
        }
        
        return ptpStyleModels
    }()
    
    //输入框内容
    var promptText:String = "" {
        didSet{
            isCanGennerateBlock?(isCanGennerate)
        }
    }
    
    //选择的生成图片的 type
    var gennerateType:TSGennerateType = .poster{
        didSet{
            isCanGennerateBlock?(isCanGennerate)
        }
    }

    //选择的 prompt 类型
    var selectPromptModel:TSPTPStyleModel?{
        didSet{
            isCanGennerateBlock?(isCanGennerate)
        }
    }
    
    //可生成状态变化 block
    var isCanGennerateBlock:((Bool)->Void)?
}


extension TSTextGeneralPicVM {
    //是否满足生成条件
    var isCanGennerate:Bool {
        if  selectPromptModel != nil ,
            promptText.replacingOccurrences(of: " ", with: "").count > 0
        {
            return true
        }
        return false
    }


    var prompt:String{
        var prompt = promptText
        if let selectPromptModel = selectPromptModel {
            prompt+=", \(selectPromptModel.prompt)"
        }
        return prompt
    }

    func saveModel(model:TSActionInfoModel){
        if gennerateType == .poster {
            TSPosterHistory.saveModel(model: model)
        }else if gennerateType == .photo{
            TSPhotoHistory.saveModel(model: model)
        }
    }
}
