package com.storlead.user.api;

import com.storlead.framework.common.result.Result;
import com.storlead.user.pojo.entity.TenantEnterpriseEntity;
import com.storlead.user.service.ITenantEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 企业租户主表 HTTP 接口
 */
@RestController
@RequestMapping("/sys/tenant/enterprise")
@Api(tags = "租户: 企业租户")
public class TenantEnterpriseApiController {

    @Resource
    private ITenantEnterpriseService tenantEnterpriseService;

    @PostMapping("/{id}")
    @ApiOperation("按主键查询")
    public Result<TenantEnterpriseEntity> getById(@PathVariable Long id) {
        return Result.result(tenantEnterpriseService.getById(id));
    }

    @PostMapping("/by-tenant")
    @ApiOperation("按租户ID查询")
    public Result<TenantEnterpriseEntity> getByTenantId(
            @ApiParam(value = "租户ID", required = true) @RequestParam Long tenantId) {
        return Result.result(tenantEnterpriseService.getByTenantId(tenantId));
    }

    @PostMapping("/save")
    @ApiOperation("新增或更新（有主键则更新）")
    public Result<Boolean> save(@RequestBody TenantEnterpriseEntity entity) {
        return Result.result(tenantEnterpriseService.saveOrUpdate(entity));
    }

    @PostMapping("/delete")
    @ApiOperation("逻辑删除")
    public Result<Boolean> remove(@PathVariable Long id) {
        return Result.result(tenantEnterpriseService.lgDelete(id));
    }
}
