package com.ffii.fhsmsc.modules.pet_information.web;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ffii.core.response.IdRes;
import com.ffii.core.response.RecordsRes;
import com.ffii.core.utils.CriteriaArgsBuilder;
import com.ffii.fhsmsc.modules.pet_information.req.pet_informationReq;
import com.ffii.fhsmsc.modules.pet_information.service.pet_informationService;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;

@RestController
@RequestMapping("/pet_information")
public class pet_informationController {
    private static final Logger logger = LoggerFactory.getLogger(pet_informationController.class);
    private pet_informationService pet_informationService;

    public pet_informationController(
		pet_informationService pet_informationService
		) {
		this.pet_informationService = pet_informationService;
	}

    @GetMapping("/list")
	public RecordsRes<Map<String, Object>> listJson(HttpServletRequest request) throws ServletRequestBindingException {
        logger.info("Received list request with parameters: {}", request.getParameterMap());
        Map<String, Object> args = CriteriaArgsBuilder.withRequest(request)
                .addInteger("owner_id")
                .build();
        logger.info("Built args: {}", args);
        return new RecordsRes<>(pet_informationService.search(args));
	}
	
    @PostMapping("/save")
	public IdRes saveOrUpdate(@RequestBody @Valid pet_informationReq req) {
		return new IdRes(pet_informationService.saveOrUpdate(req).getId());
	}
}
