package com.ecep.contract.task;

import com.ecep.contract.MessageHolder;
import com.ecep.contract.WebSocketClientTasker;
import com.ecep.contract.vo.VendorVo;

import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 供应商文件重建任务器客户端实现
 * 用于通过WebSocket与服务器通信，重建供应商相关文件
 */
public class VendorReBuildFilesTasker extends Tasker<Object> implements WebSocketClientTasker {
    private static final Logger logger = LoggerFactory.getLogger(VendorReBuildFilesTasker.class);
    
    @Getter
    @Setter
    private VendorVo vendor;
    
    @Getter
    protected boolean modified = false;

    @Override
    public String getTaskName() {
        return "VendorReBuildFilesTasker";
    }

    @Override
    public void updateProgress(long current, long total) {
        super.updateProgress(current, total);
    }

    @Override
    protected Object execute(MessageHolder holder) throws Exception {
        updateTitle("重建供应商文件");
        if (vendor == null) {
            holder.addMessage(java.util.logging.Level.SEVERE, "供应商信息不能为空");
            return null;
        }
        return callRemoteTask(holder, getLocale(), vendor.getId());
    }

    /**
     * 处理从服务器返回的修改状态
     * 当服务器端更新此属性时，客户端会接收到更新
     * 
     * @param modified 文件是否被修改
     */
    public void setModified(boolean modified) {
        this.modified = modified;
    }
}
