package org.jerrymouse.cc.site.store;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;

import org.jerrymouse.cc.site.bean.User;
import org.jerrymouse.cc.site.store.cc.CCStoreManager;
import org.jerrymouse.cc.site.store.file.FileStoreManager;
import org.jerrymouse.cc.site.store.ftp.FtpStoreConfig;
import org.jerrymouse.cc.site.store.ftp.FtpStoreManager;

@Embeddable
public class StoreConfig {
	public static final String CCSTORAGE = "ccstorage";
	@Column
	private FtpStoreConfig ftpStoreConfig;
	@Column(name = "store_type")
	private String type;
	@Transient
	public static final String FTP = "ftp";
	public static final String FILE = "file";

	public StoreManager getStoreManager(User user) {
		if (type.equals(FTP)) {
			FtpStoreManager storeManager = new FtpStoreManager();
			storeManager.setFtpFileConfig(ftpStoreConfig);
			return storeManager;
		} else if (type.equals(CCSTORAGE)) {
			return new CCStoreManager(user.getUsername());
		} else if (FILE.equals(type)) {
			return new FileStoreManager(user.getUsername());
		}
		return null;
	}

	public FtpStoreConfig getFtpStoreConfig() {
		return ftpStoreConfig;
	}

	public void setFtpStoreConfig(FtpStoreConfig ftpStoreConfig) {
		this.ftpStoreConfig = ftpStoreConfig;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
