package cn.iocoder.yudao.module.system.controller.admin.languagetype;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.languagetype.vo.LanguageTypeCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.languagetype.vo.LanguageTypePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.languagetype.vo.LanguageTypeRespVO;
import cn.iocoder.yudao.module.system.controller.admin.languagetype.vo.LanguageTypeUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.languagetype.LanguageTypeConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.languagetype.LanguageTypeDO;
import cn.iocoder.yudao.module.system.service.languagetype.LanguageTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 语言类型")
@RestController
@RequestMapping("/system/language-type")
@Validated
public class LanguageTypeController {

    @Resource
    private LanguageTypeService languageTypeService;

    @PostMapping("/create")
    @ApiOperation("创建语言类型")
    @PreAuthorize("@ss.hasPermission('system:language-type:create')")
    public CommonResult<Long> createLanguageType(@Valid @RequestBody LanguageTypeCreateReqVO createReqVO) {
        return success(languageTypeService.createLanguageType(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新语言类型")
    @PreAuthorize("@ss.hasPermission('system:language-type:update')")
    public CommonResult<Boolean> updateLanguageType(@Valid @RequestBody LanguageTypeUpdateReqVO updateReqVO) {
        languageTypeService.updateLanguageType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除语言类型")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('system:language-type:delete')")
    public CommonResult<Boolean> deleteLanguageType(@RequestParam("id") Long id) {
        languageTypeService.deleteLanguageType(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得语言类型")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('system:language-type:query')")
    public CommonResult<LanguageTypeRespVO> getLanguageType(@RequestParam("id") Long id) {
        LanguageTypeDO languageType = languageTypeService.getLanguageType(id);
        return success(LanguageTypeConvert.INSTANCE.convert(languageType));
    }

    @GetMapping("/list")
    @ApiOperation("获得语言类型列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('system:language-type:query')")
    public CommonResult<List<LanguageTypeRespVO>> getLanguageTypeList(@RequestParam("ids") Collection<Long> ids) {
        List<LanguageTypeDO> list = languageTypeService.getLanguageTypeList(ids);
        return success(LanguageTypeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/all")
    @ApiOperation("获得所有的语言类型")
    @PreAuthorize("@ss.hasPermission('system:language-type:query')")
    public CommonResult<List<LanguageTypeRespVO>> getAllLanguageTypeList() {
        List<LanguageTypeDO> list = languageTypeService.getAllLanguageTypeList();
        return success(LanguageTypeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得语言类型分页")
    @PreAuthorize("@ss.hasPermission('system:language-type:query')")
    public CommonResult<PageResult<LanguageTypeRespVO>> getLanguageTypePage(@Valid LanguageTypePageReqVO pageVO) {
        PageResult<LanguageTypeDO> pageResult = languageTypeService.getLanguageTypePage(pageVO);
        return success(LanguageTypeConvert.INSTANCE.convertPage(pageResult));
    }

}
