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.User_authorityReq;
import com.ffii.fhsmsc.modules.User_group.service.User_authorityService;

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

@RestController
@RequestMapping("/user_authority")
public class User_authorityController {
    private User_authorityService user_authorityService;

    public User_authorityController(
		User_authorityService user_authorityService
		) {
		this.user_authorityService = user_authorityService;
	}

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

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