package com.ecep.contract.converter;

import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.ecep.contract.service.ProductUsageService;
import com.ecep.contract.vo.ProductUsageVo;

import jakarta.annotation.PostConstruct;

public class ProductUsageStringConverter extends StringConverter<ProductUsageVo> {
    private ProductUsageService service;

    public ProductUsageStringConverter(ProductUsageService service) {
        this.service = service;
    }

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

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


}