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.SysIndustryBo;
import org.dromara.system.domain.vo.SysIndustryVo;
import org.dromara.system.service.ISysIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    private final ISysIndustryService industryService;

    /**
     * 查询行业分类列表
     */
    @GetMapping("/list")
    public R<List<SysIndustryVo>> list(SysIndustryBo bo) {
        return R.ok(industryService.queryList(bo));
    }

    /**
     * 查询行业分类列表(忽略租户)
     */
    @GetMapping("/open/list")
    public R<List<SysIndustryVo>> openList(SysIndustryBo bo) {
        return R.ok(industryService.queryListIgnoreTenant(bo));
    }

    /**
     * 获取行业分类详情
     */
    @GetMapping("/{industryId}")
    public R<SysIndustryVo> getInfo(@PathVariable Long industryId) {
        return R.ok(industryService.queryById(industryId));
    }

    /**
     * 新增行业分类
     */
    @Log(title = "行业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysIndustryBo bo) {
        return industryService.insertByBo(bo) ? R.ok() : R.fail();
    }

    /**
     * 修改行业分类
     */
    @Log(title = "行业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysIndustryBo bo) {
        return industryService.updateByBo(bo) ? R.ok() : R.fail();
    }

    /**
     * 删除行业分类
     */
    @Log(title = "行业分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{industryId}")
    public R<Void> remove(@PathVariable Long industryId) {
        return industryService.deleteById(industryId) ? R.ok() : R.fail();
    }
}
