package org.dromara.system.controller.system;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysIndustrySkillBo;
import org.dromara.system.domain.vo.SysIndustrySkillVo;
import org.dromara.system.service.ISysIndustrySkillService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/industry/skill")
public class SysIndustrySkillController extends BaseController {

    private final ISysIndustrySkillService skillService;

    /**
     * 查询职位列表
     */
    @GetMapping("/list")
    public R<List<SysIndustrySkillVo>> list(SysIndustrySkillBo bo) {
        return R.ok(skillService.queryList(bo));
    }

    /**
     * 查询职位列表(忽略租户)
     */
    @GetMapping("/open/list")
    public R<List<SysIndustrySkillVo>> openList(SysIndustrySkillBo bo) {
        return R.ok(skillService.queryListIgnoreTenant(bo));
    }

    /**
     * 获取职位详情
     */
    @GetMapping("/{skillId}")
    public R<SysIndustrySkillVo> getInfo(@PathVariable Long skillId) {
        return R.ok(skillService.queryById(skillId));
    }

    /**
     * 新增职位
     */
    @Log(title = "职位技能", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysIndustrySkillBo bo) {
        return skillService.insertByBo(bo) ? R.ok() : R.fail();
    }

    /**
     * 修改职位
     */
    @Log(title = "职位技能", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysIndustrySkillBo bo) {
        return skillService.updateByBo(bo) ? R.ok() : R.fail();
    }

    /**
     * 删除职位
     */
    @Log(title = "职位技能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{skillId}")
    public R<Void> remove(@PathVariable Long skillId) {
        return skillService.deleteById(skillId) ? R.ok() : R.fail();
    }
}
