package com.ecep.contract.converter;

import com.ecep.contract.service.ProjectIndustryService;
import com.ecep.contract.vo.ProjectIndustryVo;

import javafx.util.StringConverter;

public class ProjectIndustryStringConverter extends StringConverter<ProjectIndustryVo> {
    private ProjectIndustryService service;

    public ProjectIndustryStringConverter(ProjectIndustryService service) {
        this.service = service;
    }

    @Override
    public String toString(ProjectIndustryVo object) {
        if (object == null) {
            return "";
        }
        return object.getCode() + " " + object.getName();
    }

    @Override
    public ProjectIndustryVo fromString(String string) {
        if (string == null || string.isEmpty()) {
            return null;
        }
        return service.findByName(string);
    }

}