package com.ecep.contract.converter;

import com.ecep.contract.service.ProductTypeService;
import com.ecep.contract.vo.ProductTypeVo;

import javafx.util.StringConverter;

public class ProductTypeStringConverter extends StringConverter<ProductTypeVo> {
    private final ProductTypeService service;

    public ProductTypeStringConverter(ProductTypeService service) {
        this.service = service;
    }

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

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


}