package com.hys.app.controller.erp.use;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.security.model.Admin;
import com.hys.app.model.erp.entity.*;
import com.hys.app.service.erp.CompanyManager;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;

@Api(tags = "公司")
@RestController
@RequestMapping("/admin/erp/company")
@AllArgsConstructor
public class CompanyController {

    private CompanyManager companyManager;
    @PostMapping("createCompany")
    @ApiOperation(value = "创建公司")
    @Log(client = LogClient.admin, detail = "创建名称为[${companyDO.name}]的公司信息")
    public Long createCompany(@Valid @RequestBody CompanyDO companyDO) {
        return companyManager.createCompany(companyDO);
    }

    @PostMapping("updateCompany/{id}")
    @ApiOperation(value = "更新公司")
    @Log(client = LogClient.admin, detail = "修改名称为[${companyDO.name}]的公司信息")
    public Long updateCompany(@Valid @RequestBody CompanyUpdateDO companyUpdateDO, @PathVariable Long id) {
        return companyManager.updateCompany(companyUpdateDO, id);
    }
    @PostMapping("renewCompany/difference/{id}")
    @ApiOperation(value = "公司续费未到期更换套餐")
    @Log(client = LogClient.admin, detail = "名称为[${companyDO.name}]的公司进行了续费")
    public BigDecimal renewCompanyDifference(@PathVariable Long id) {
        return companyManager.renewCompanyDifference(id);
    }

    @PostMapping("renewCompany/{id}")
    @ApiOperation(value = "公司续费")
    @Log(client = LogClient.admin, detail = "名称为[${companyDO.name}]的公司进行了续费")
    public Long renewCompany(@Valid @RequestBody CompanyRenewDO companyUpdateDO, @PathVariable Long id) {
        return companyManager.renewCompany(companyUpdateDO, id);
    }

    @GetMapping("getOne/{id}")
    @ApiOperation(value = "获取公司详情")
    public CompanyVO getOneCompany(@PathVariable Long id) {
        return companyManager.getOneCompany(id);
    }
    @GetMapping("getPage")
    @ApiOperation(value = "分页")
    public IPage<CompanyVO> getPage(CompanyQuery query) {
        return companyManager.getPage(query);
    }
}
