package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.CompanyServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.CompanyVO;
import com.xunhong.erp.turbo.base.dto.PageDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "Company", description = "公司管理管理")
@RestController("operationCompanyController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class CompanyController {

	@DubboReference(version = "1.0.0")
	private final CompanyServiceI companyService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_VIEW})
	@GetMapping("listCompany")
	@Operation(summary = "公司管理列表", method = "GET")
	public MultiResponse<CompanyVO> listCompany(@ModelAttribute @Validated CompanyListQry companyListQry) {
		return MultiResponse.of(companyService.list(companyListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_CREATE})
	@PostMapping("createCompany")
	@Operation(summary = "创建公司管理", method = "POST")
	public SingleResponse<CompanyVO> createCompany(@RequestBody @Validated CompanyCreateCmd companyCreateCmd) {
		return SingleResponse.of(companyService.create(companyCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_VIEW})
	@GetMapping("showCompany")
	@Operation(summary = "公司管理详情", method = "GET")
	public SingleResponse<CompanyVO> showCompany(@ModelAttribute @Validated CompanyShowQry companyShowQry) {
		return SingleResponse.of(companyService.show(companyShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_VIEW})
	@GetMapping("pageCompany")
	@Operation(summary = "公司管理列表", method = "GET")
	public PageResponse<CompanyVO> pageCompany(@ModelAttribute @Validated CompanyPageQry companyPageQry) {
		PageDTO<CompanyVO> page = companyService.page(companyPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_UPDATE})
	@RequestMapping(value = "updateCompany", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "公司管理更新", method = "PATCH")
	public SingleResponse<CompanyVO> updateCompany(@RequestBody @Validated CompanyUpdateCmd companyUpdateCmd) {
		return SingleResponse.of(companyService.update(companyUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_DELETE})
	@DeleteMapping("destroyCompany")
	@Operation(summary = "公司管理删除", method = "DELETE")
	public Response destroyCompany(@RequestBody @Validated CompanyDestroyCmd companyDestroyCmd) {
		companyService.destroy(companyDestroyCmd);
		return Response.buildSuccess();
	}
}
