package com.ningdatech.pmapi.meta.controller;


import com.ningdatech.pmapi.meta.manage.MetaManage;
import com.ningdatech.pmapi.meta.model.po.ReqAddTagTypePO;
import com.ningdatech.pmapi.meta.model.po.ReqTagListPO;
import com.ningdatech.pmapi.meta.model.po.ReqTagQueryPO;
import com.ningdatech.pmapi.meta.model.vo.ResTagListVO;
import com.ningdatech.pmapi.meta.model.vo.ResTagTreeVO;
import com.ningdatech.pmapi.meta.model.vo.ResTagTypeVO;
import com.ningdatech.pmapi.meta.validate.TagListRequestValidator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liuxinxin
 * @since 2022-07-21
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/api/v1/meta")
@Api(value = "MetaController", tags = "基础数据接口")
public class MetaTagManageController {

    /**
     * 专家标签的缓存时间设置为5分钟，单位秒
     */
    private static final Long MAX_AGE = 5 * 60L;
    /**
     * max-age=86400
     */
    private static final String MAX_AGE_STR = "max-age=" + MAX_AGE;
    private final MetaManage metaManage;

    @PostMapping("/tag")
    @ApiOperation("获取专家标签的树状结构")
    public List<ResTagTreeVO> getRegionTree(HttpServletResponse response, @RequestBody ReqTagListPO request) {
        response.setHeader("Cache-Control", MAX_AGE_STR);
        TagListRequestValidator.tagListRequestValidator(request);
        return metaManage.getTagTree(request);
    }

    @PostMapping("/tag/query")
    @ApiOperation("标签查询接口")
    public List<ResTagListVO> tagQuery(@Valid @RequestBody ReqTagQueryPO reqTagQueryPO) {
        return metaManage.tagQuery(reqTagQueryPO);
    }

    @PostMapping("/tag-tyoe/list")
    @ApiOperation("获取标签分类列表")
    public List<ResTagTypeVO> tagTypeList() {
        return metaManage.tagTypeList();
    }

    @PostMapping("/add/tag-type")
    @ApiOperation("新增标签分类")
    public void addTagType(@Valid @RequestBody ReqAddTagTypePO request) {
        metaManage.addTagType(request);
    }

    @PostMapping("/remove/tag/{tagCode}")
    @ApiOperation("删除标签")
    public void removeTagName(@PathVariable String tagCode) {
        metaManage.removeTagName(tagCode);
    }

}
