package com.purui.prims.headless.server.rest;

import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.auth.api.authentication.utils.UserHolder;
import com.purui.prims.headless.api.pojo.request.DecoratorTypeReq;
import com.purui.prims.headless.api.pojo.response.DecoratorTypeResp;
import com.purui.prims.headless.server.service.DecoratorTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 修饰词类型
 *
 * @author charlie
 * @date 2024/6/24
 */
@RestController
@RequestMapping({"/api/semantic/decoratorType"})
public class DecoratorTypeController {

    private final DecoratorTypeService decoratorTypeService;

    public DecoratorTypeController(DecoratorTypeService decoratorTypeService) {
        this.decoratorTypeService = decoratorTypeService;
    }

    @ApiOperation(value = "新建/修改类型")
    @PostMapping
    public boolean save(@RequestBody DecoratorTypeReq decoratorReq, HttpServletRequest request,
                        HttpServletResponse response) {
        User user = UserHolder.findUser(request, response);
        return decoratorTypeService.saveOrUpdate(decoratorReq, user);
    }

    @GetMapping("/getDecorator/{id}")
    public DecoratorTypeResp getType(@PathVariable int id) {
        return decoratorTypeService.getType(id);
    }

    @ApiOperation(value = "类型列表")
    @PostMapping("/list")
    public List<DecoratorTypeResp> getDecorators(@RequestBody DecoratorTypeReq decoratorReq) {
        return decoratorTypeService.getTypes(decoratorReq);
    }
}
