//package dev.fyloz.trial.colorrecipesexplorer.web.controller.thymeleaf.creators;
//
//import dev.fyloz.trial.colorrecipesexplorer.exception.SimdutException;
//import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityAlreadyExistsException;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ModelResponseBuilder;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseCode;
//import dev.fyloz.trial.colorrecipesexplorer.web.response.ResponseDataType;
//import dev.fyloz.trial.colorrecipesexplorer.model.Material;
//import dev.fyloz.trial.colorrecipesexplorer.services.model.MaterialService;
//import dev.fyloz.trial.colorrecipesexplorer.services.model.MaterialTypeService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.lang.Nullable;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.validation.Valid;
//
//import java.util.Optional;
//
//import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.CREATOR_MATERIAL;
//
//@Controller
//public class MaterialCreatorController {
//
//    private MaterialService materialService;
//    private MaterialTypeService materialTypeService;
//
//    @Autowired
//    public MaterialCreatorController(MaterialService materialService, MaterialTypeService materialTypeService) {
//        this.materialService = materialService;
//        this.materialTypeService = materialTypeService;
//    }
//
//    @GetMapping(CREATOR_MATERIAL)
//    public ModelAndView getPage(ModelAndView model, Material material) {
//        return new ModelResponseBuilder(model)
//                .withView(CREATOR_MATERIAL)
////                .addResponseData(ResponseDataType.MATERIAL, material)
////                .addResponseData(ResponseDataType.MATERIAL_TYPES, materialTypeService.getAll())
//                .build();
//    }
//
//    @PostMapping(value = CREATOR_MATERIAL, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//    public ModelAndView createMaterial(@Valid Material material, MultipartFile simdut) {
//        ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
//
//        try {
//            materialService.save(material, simdut);
//            return getPage(
//                    modelResponseBuilder.addResponseCode(ResponseCode.SUCCESS_SAVING_MATERIAL, material.getName()).build(),
//                    new Material()
//            );
//        } catch (EntityAlreadyExistsException ex) {
//            modelResponseBuilder.addResponseCode(ResponseCode.MATERIAL_ALREADY_EXIST, material.getName());
//        } catch (SimdutException ex) {
//            modelResponseBuilder.addResponseCode(ResponseCode.SUCCESS_SAVING_MATERIAL, material.getName());
//            modelResponseBuilder.addResponseCode(ResponseCode.ERROR_SAVING_SIMDUT);
//        }
//
//        return getPage(modelResponseBuilder.build(), material);
//    }
//}
