package cn.stylefeng.team.meta.modular.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.meta.modular.entity.MetaUserDict;
import cn.stylefeng.team.meta.modular.pojo.request.MetaUserDictRequest;
import cn.stylefeng.team.meta.modular.pojo.response.UserDictTypeResponse;
import cn.stylefeng.team.meta.modular.service.MetaUserDictService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "元数据-用户字典")
public class MetaUserDictController {

    @Resource
    private MetaUserDictService metaUserDictService;

    @GetResource(name = "获取字典类型列表", path = "/metaUserDict/dictType/list")
    public ResponseData<List<UserDictTypeResponse>> dictTypeList(MetaUserDictRequest metaUserDictRequest) {
        return new SuccessResponseData<>(metaUserDictService.findDictTypeList(metaUserDictRequest));
    }

    @PostResource(name = "删除字典类型", path = "/metaUserDict/dictType/delete")
    public ResponseData<?> deleteDictType(@RequestBody @Validated(MetaUserDictRequest.delete.class) MetaUserDictRequest metaUserDictRequest) {
        metaUserDictService.del(metaUserDictRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "新增字典类型", path = "/metaUserDict/dictType/add")
    public ResponseData<?> addDictType(@RequestBody @Validated(MetaUserDictRequest.add.class) MetaUserDictRequest metaUserDictRequest) {
        metaUserDictService.add(metaUserDictRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑字典类型", path = "/metaUserDict/dictType/edit")
    public ResponseData<?> editDictType(@RequestBody @Validated(MetaUserDictRequest.edit.class) MetaUserDictRequest metaUserDictRequest) {
        metaUserDictService.edit(metaUserDictRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "获取字典详情 + 字典列表值", path = "/metaUserDict/dictType/detail")
    public ResponseData<MetaUserDict> detail(@Validated(MetaUserDictRequest.detail.class) MetaUserDictRequest metaUserDictRequest) {
        return new SuccessResponseData<>(metaUserDictService.detail(metaUserDictRequest));
    }

    @PostResource(name = "更新字典项列表", path = "/metaUserDict/dict/updateDictItemList")
    public ResponseData<?> updateDictItemList(@RequestBody @Validated(MetaUserDictRequest.updateItem.class) MetaUserDictRequest metaUserDictRequest) {
        metaUserDictService.updateDictItemList(metaUserDictRequest);
        return new SuccessResponseData<>();
    }

}
