package com.ecep.contract.converter;

import com.ecep.contract.Desktop;
import com.ecep.contract.service.VendorTypeService;
import com.ecep.contract.vo.VendorTypeLocalVo;
import javafx.util.StringConverter;

public class VendorTypeStringConverter extends StringConverter<VendorTypeLocalVo> {
    private final VendorTypeService service;

    public VendorTypeStringConverter(VendorTypeService service) {
        this.service = service;
    }

    @Override
    public String toString(VendorTypeLocalVo object) {
        return object.getValue();
    }

    @Override
    public VendorTypeLocalVo fromString(String string) {
        return service.findByLocaleAndValue(Desktop.instance.getActiveEmployee().localeProperty().get(), string);
    }
}
