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

import java.util.Map;

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.User_group.req.UserDelegationReq;
import com.ffii.fhsmsc.modules.User_group.service.UserDelegationService;

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

@RestController
@RequestMapping("/userDelegation")
public class UserDelegationController {
    private UserDelegationService userDelegationService;

    public UserDelegationController(
		UserDelegationService userDelegationService
		) {
		this.userDelegationService = userDelegationService;
	}

    @GetMapping("/list")
	public RecordsRes<Map<String, Object>> listJson(HttpServletRequest request) throws ServletRequestBindingException {
		return new RecordsRes<>(userDelegationService.search(
				CriteriaArgsBuilder.withRequest(request)
						.addInteger("userId") 
						// .addInteger(Params.ID)
						// .addStringLike(Params.NAME)
						// .addStringLike("description")
						// .addInteger("userId")
						.build()));
	}

    @PostMapping("/save")
	public IdRes saveOrUpdate(@RequestBody @Valid UserDelegationReq req) {
		return new IdRes(userDelegationService.saveOrUpdate (req).getId());
	}
}

