package com.jeesharp.business.modules.food.controller;

import com.jeesharp.business.modules.food.application.FoodCompanyEmployeeApplicationService;
import com.jeesharp.business.modules.food.dto.FoodCompanyEmployeeSaveDTO;
import com.jeesharp.business.modules.food.entity.FoodCompanyEmployee;
import com.jeesharp.business.modules.food.vo.FoodCompanyEmployeeListVO;
import com.jeesharp.business.modules.food.vo.FoodCompanyEmployeeQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/food/companyEmployee/v1")
@Tag(name = "企业人员管理")
@AllArgsConstructor
public class FoodCompanyEmployeeController extends BaseController {

    private final FoodCompanyEmployeeApplicationService foodCompanyEmployeeApplicationService;

    @Operation(summary = "获取列表（分页）")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<FoodCompanyEmployeeListVO>> list(@RequestBody FoodCompanyEmployeeQueryVO query) {
        return AjaxResult.okData(foodCompanyEmployeeApplicationService.findEmployeePage(new Page<FoodCompanyEmployee>(query), query));
    }

    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:info')")
    @GetMapping("info")
    public AjaxResult<FoodCompanyEmployeeListVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(foodCompanyEmployeeApplicationService.getEmployee(id));
    }

    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:save')")
    @PostMapping("save")
    public AjaxResult<Void> save(@RequestBody @Valid FoodCompanyEmployeeSaveDTO dto) {
        foodCompanyEmployeeApplicationService.saveEmployee(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "冻结")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:freeze')")
    @PostMapping("freeze")
    public AjaxResult<Void> freeze(@RequestParam("id") String id) {
        foodCompanyEmployeeApplicationService.freezeEmployee(id);
        return AjaxResult.ok("冻结成功");
    }

    @Operation(summary = "恢复")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:restore')")
    @PostMapping("restore")
    public AjaxResult<Void> restore(@RequestParam("id") String id) {
        foodCompanyEmployeeApplicationService.restoreEmployee(id);
        return AjaxResult.ok("恢复成功");
    }

    @Operation(summary = "解绑")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:unbind')")
    @PostMapping("unbind")
    public AjaxResult<Void> unbind(@RequestParam("id") String id) {
        foodCompanyEmployeeApplicationService.unbindEmployee(id);
        return AjaxResult.ok("解绑成功");
    }

    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('manager:business:food:companyEmployee:delete')")
    @GetMapping("delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        foodCompanyEmployeeApplicationService.deleteEmployee(ids);
        return AjaxResult.ok("删除成功");
    }
}
