package com.ecep.contract.converter;

import com.ecep.contract.Desktop;
import com.ecep.contract.service.CompanyCustomerFileTypeService;
import com.ecep.contract.vo.CustomerFileTypeLocalVo;

import javafx.util.StringConverter;

/**
 * 客户文件类型字符串转换器
 */
public class CustomerFileTypeStringConverter extends StringConverter<CustomerFileTypeLocalVo> {
    private final CompanyCustomerFileTypeService service;

    public CustomerFileTypeStringConverter(CompanyCustomerFileTypeService service) {
        this.service = service;
    }

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

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