package com.ecep.contract.converter;

import com.ecep.contract.service.ProjectSaleTypeService;
import com.ecep.contract.vo.ProjectSaleTypeVo;

import javafx.util.StringConverter;

public class ProjectSaleTypeStringConverter extends StringConverter<ProjectSaleTypeVo> {
    private final ProjectSaleTypeService service;

    public ProjectSaleTypeStringConverter(ProjectSaleTypeService service) {
        this.service = service;
    }

    @Override
    public String toString(ProjectSaleTypeVo type) {
        return type == null ? "" : type.getCode() + " " + type.getName();
    }

    @Override
    public ProjectSaleTypeVo fromString(String string) {
        return service.findByName(string);
    }
}